Class: Nasty::Lazy
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(factory = ->(key) { key.new }, *arguments) ⇒ Lazy
constructor
A new instance of Lazy.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
#initialize(factory = ->(key) { key.new }, *arguments) ⇒ Lazy
Returns a new instance of Lazy.
3 4 5 6 |
# File 'lib/nasty/lazy.rb', line 3 def initialize(factory = ->(key) { key.new }, *arguments) @factory = factory @arguments = arguments end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
8 9 10 11 |
# File 'lib/nasty/lazy.rb', line 8 def method_missing(name, *args, &block) @target ||= @factory.call(*@arguments) @target.send(name, args, &block) end |