This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]" : "[ ]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gifts = ["iphone", "macbook", "carro", "par de meias"] | |
| def list(gifts) | |
| gifts.each_with_index do |item, index| | |
| puts "#{index + 1} - #{item}" | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def acronymizer(sentence) | |
| words = sentence.split | |
| acronym = "" | |
| words.each do |word| | |
| acronym += word.slice(0).upcase | |
| end | |
| acronym | |
| end | |
| describe "#acronymizer" do |
NewerOlder