Created
September 5, 2014 18:46
-
-
Save stoffie/bec5673ff42edf494ecd 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
#!/usr/local/bin/ruby -w | |
class Cat | |
def initialize name | |
name = name.upcase | |
define_singleton_method :name do | |
name | |
end | |
define_singleton_method :meow do | |
puts "Meow meow #{name}" | |
end | |
end | |
end | |
Catburger = Class.new do | |
self_hash = Hash.new { |h,k| h[k] = Hash.new } | |
define_method :initialize do |cat| | |
self_hash[self][:cat] = cat | |
end | |
define_method :process do | |
cat = self_hash[self][:cat] | |
cat.meow | |
puts "Processing now your catburger" | |
puts "Your catburger is now ready" | |
end | |
end | |
derpy = Cat.new "derp" | |
burger = Catburger.new derpy | |
burger.process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment