Skip to content

Instantly share code, notes, and snippets.

View RobertoBarros's full-sized avatar

Roberto Barros RobertoBarros

  • São Paulo, Brazil
  • 20:19 (UTC -03:00)
View GitHub Profile
@RobertoBarros
RobertoBarros / savannah.rb
Created November 21, 2026 20:58
batch_2406_livecode_savannah
# Define an Animal with an initialize(name) constructor, exposing its name.
# Define three Lion, Meerkat and Warthog classes
# Implement a #talk instance method which returns a sentence like "Simba roars" for each animal. (Hint: Meerkats bark and Warthog grunt)
# Implement a ::habitats class method which will return an array of animal habitats: Jungle, Desert, Grassland, Forest, Ocean, Mountain.
# Add an #eat(food) instance method in Animal which returns a sentence like “Timon eats a scorpion”. Then override this method for the Lion class, and return a sentence like “Simba eats a gazelle. Law of the Jungle!”
class Animal
attr_reader :name
@RobertoBarros
RobertoBarros / gifts.rb
Created November 14, 2026 20:52
batch_2406_reboot_gifts_list_part_5
require 'csv'
require 'open-uri'
require 'nokogiri'
FILEPATH = "gifts.csv"
def list(gifts)
puts "The list is empty" if gifts.count.zero?
gifts.each_with_index do |item, index|
check = item[:bought] ? "[X]" : "[ ]"
@RobertoBarros
RobertoBarros / gifts.rb
Created November 14, 2026 19:39
batch_2406_reboot_gifts_list_part_4
require 'csv'
FILEPATH = "gifts.csv"
def list(gifts)
puts "The list is empty" if gifts.count.zero?
gifts.each_with_index do |item, index|
check = item[:bought] ? "[X]" : "[ ]"
puts "#{check} #{index + 1} - #{item[:gift]}"
end
end
@RobertoBarros
RobertoBarros / gifts.rb
Created November 14, 2026 18:24
batch_2406_reboot_gifts_list_part_3
require 'csv'
FILEPATH = "gifts.csv"
def list(gifts)
puts "The list is empty" if gifts.count.zero?
gifts.each_with_index do |item, index|
puts "#{index + 1} - #{item}"
end
end
@RobertoBarros
RobertoBarros / gifts.rb
Created November 14, 2026 17:19
batch_2406_reboot_gifts_list_part_2
gifts = []
def list(gifts)
puts "The list is empty" if gifts.count.zero?
gifts.each_with_index do |item, index|
puts "#{index + 1} - #{item}"
end
end
@RobertoBarros
RobertoBarros / gifts.rb
Created November 14, 2026 15:25
batch_2406_reboot_gifts_list_part_1
gifts = ["iphone", "macbook", "carro", "par de meias"]
def list(gifts)
gifts.each_with_index do |item, index|
puts "#{index + 1} - #{item}"
end
end
@RobertoBarros
RobertoBarros / xmas.rb
Created October 30, 2026 00:55
batch_2406_livecode_xmas
# Importa a biblioteca Date, que permite trabalhar com datas.
require 'date'
# Define um método que recebe uma data e retorna quantos dias faltam para o Natal.
def days_to_xmas(today)
# Cria uma data para o Natal (25 de dezembro) do mesmo ano da data recebida.
natal = Date.new(today.year, 12, 25)
# Verifica se a data recebida é posterior ao Natal deste ano.
@RobertoBarros
RobertoBarros / citizen.rb
Created October 28, 2026 21:11
batch_2395_livecode_citizen_and_slot_machine
class Citizen
def initialize(first_name, last_name, age)
@first_name = first_name
@last_name = last_name
@age = age
end
def can_vote?
@age >= 18
@RobertoBarros
RobertoBarros / acronym.rb
Created October 22, 2026 21:12
batch_2395_livecode_caesar
def acronymizer(sentence)
sentence.split.map { |word| word.slice(0).upcase }.join
end
describe "#acronymizer" do
it "return empty for sentence is empty" do
actual = acronymizer("")
expect(actual).to eq("")
end
@RobertoBarros
RobertoBarros / acronym.rb
Last active October 21, 2026 21:03
batch_2395_livecode_acronym
def acronymizer(sentence)
words = sentence.split
acronym = ""
words.each do |word|
acronym += word.slice(0).upcase
end
acronym
end
describe "#acronymizer" do