-
-
Save oleander/aa48167bfc5268a347bc 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
class Base | |
class Config | |
def id(value) | |
@id = value | |
end | |
def to_s | |
@id | |
end | |
end | |
def self.config(&blk) | |
@@config ||= Config.new | |
@@config.instance_eval(&blk) | |
end | |
def config | |
@@config | |
end | |
end | |
class This < Base | |
config do | |
id "hello1" | |
end | |
end | |
class That < Base | |
config do | |
id "hello2" | |
end | |
end | |
puts This.new.config.to_s # => hello2 | |
puts That.new.config.to_s # => hello2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment