Skip to content

Instantly share code, notes, and snippets.

@oleander

oleander/a.rb Secret

Created December 12, 2015 01:56
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 oleander/aa48167bfc5268a347bc to your computer and use it in GitHub Desktop.
Save oleander/aa48167bfc5268a347bc to your computer and use it in GitHub Desktop.
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