Created
June 4, 2012 13:20
-
-
Save shunsugai/2868330 to your computer and use it in GitHub Desktop.
ClassMacro2
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 Bar | |
class << self | |
def self.bar(method) | |
define_method(method) do | |
puts "Bar.#{method} called." | |
end | |
end | |
bar :foo | |
bar :baz | |
end | |
end | |
Bar.foo #=> Bar.foo called. | |
Bar.baz #=> Bar.baz called. | |
class Baz | |
class << self | |
class << self | |
def baz(method) | |
define_method(method) do | |
puts "Baz.#{method} called." | |
end | |
end | |
end | |
baz :foo | |
baz :bar | |
end | |
end | |
Baz.foo #=> Baz.foo called. | |
Baz.bar #=> Baz.bar called. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment