Skip to content

Instantly share code, notes, and snippets.

@stoffie
Created September 5, 2014 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoffie/bec5673ff42edf494ecd to your computer and use it in GitHub Desktop.
Save stoffie/bec5673ff42edf494ecd to your computer and use it in GitHub Desktop.
#!/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