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 Fixnum | |
def divisible_by_3? | |
self % 3 == 0 | |
end | |
def divisible_by_5? | |
self % 5 == 0 | |
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
class FizzBuzzGame | |
FIZZ = 'fizz' | |
BUZZ = 'buzz' | |
FIZZBUZZ = 'fizzbuzz' | |
def answer_for(number) | |
return FIZZBUZZ if number.divisible_by_3? and number.divisible_by_5? | |
return FIZZ if number.divisible_by_3? | |
return BUZZ if number.divisible_by_5? | |
number.value |
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 FizzBuzzGame | |
FIZZ = 'fizz' | |
BUZZ = 'buzz' | |
FIZZBUZZ = 'fizzbuzz' | |
def answer_for(number) | |
return FIZZBUZZ if divisible_by_3?(number) and divisible_by_5?(number) | |
return FIZZ if divisible_by_3?(number) | |
return BUZZ if divisible_by_5?(number) | |
number |
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 FizzBuzzGame | |
def answer_for(number) | |
return 'fizzbuzz' if number % 3 == 0 and number % 5 == 0 | |
return 'fizz' if number % 3 == 0 | |
return 'buzz' if number % 5 == 0 | |
number | |
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
class Fixnum | |
def +(other) | |
self - other | |
end | |
def *(other) | |
self / other | |
end | |
def ==(other) |
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 String | |
def to_camel_case | |
return self if self == "" | |
words = self.split | |
words[1..words.size].each { |word| word.capitalize! } | |
words.join('') | |
end | |
def to_snake_case | |
self.downcase.gsub(/\s/, '_') |
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 Dog | |
def bark | |
puts 'guau' | |
end | |
end | |
def try_my_dog | |
dog = Dog.new | |
dog.bark | |
begin |
NewerOlder