Created
May 6, 2009 17:57
-
-
Save jdunphy/107637 to your computer and use it in GitHub Desktop.
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
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 |
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
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 |
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
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