Module: LazyConst
- Defined in:
- lib/lazy_const.rb
Constant Summary collapse
- CACHE =
{}
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
Instance Method Details
#lazy_const(name, &block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/lazy_const.rb', line 9 def lazy_const(name, &block) raise Error("lazy_const requires a block") unless block_given? LazyConst::CACHE["#{self.name}.#{name}"] = nil .send(:define_method, name) do LazyConst::CACHE["#{self.name}.#{name}"] ||= block.call end end |
#meta_class ⇒ Object
5 6 7 |
# File 'lib/lazy_const.rb', line 5 def @meta_class ||= class << self; self end end |