Created
April 15, 2014 20:29
-
-
Save Supernats/10769905 to your computer and use it in GitHub Desktop.
This file contains 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 Cat | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
def self.chorus(noise_method, *cats) | |
cats.each do |cat| | |
cat.make_noise(noise_method) | |
end | |
nil | |
end | |
def make_noise(noise_method) | |
noise_method.bind(self).call | |
end | |
def meow | |
puts "#{ name } meows" | |
end | |
def purr | |
puts "#{ name} purrs" | |
end | |
end | |
e = Cat.new('earl') | |
b = Cat.new('breakfast') | |
meow = Cat.instance_method(:meow) | |
purr = Cat.instance_method(:purr) | |
Cat.chorus(purr, e, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment