Skip to content

Instantly share code, notes, and snippets.

@jdunphy
Created May 6, 2009 17:57
Show Gist options
  • Save jdunphy/107637 to your computer and use it in GitHub Desktop.
Save jdunphy/107637 to your computer and use it in GitHub Desktop.
module TheExtended
def self.extended(extensor)
raise "WHERE IS THE THING!?!?" unless extensor.constants.include?('THE_THING')
extensor.instance_eval "
def a_thing
#{extensor.name}::THE_THING
end
"
end
def using_the_thing
"I use #{a_thing}!"
end
end
module Extender
THE_THING = "the thing"
extend TheExtended
end
puts Extender.using_the_thing
module TheExtended
def self.extended(extensor)
raise "WHERE IS THE THING!?!?" unless extensor.constants.include?('THE_THING')
extensor.instance_eval "
def a_thing
'#{extensor::THE_THING}'
end
"
end
def using_the_thing
"I use #{a_thing}!"
end
end
module Extender
THE_THING = "the thing"
extend TheExtended
end
puts Extender.using_the_thing
module TheExtended
def using_the_thing
"I use #{a_thing}!"
end
def a_thing
raise "O NOSE!"
end
end
class Extender
THE_THING = "the thing"
extend TheExtended
def self.a_thing
THE_THING
end
end
puts Extender.using_the_thing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment