Class: LazyMethod
- Inherits:
-
Object
- Object
- LazyMethod
- Defined in:
- lib/lazy_method.rb,
lib/lazy_method/version.rb
Defined Under Namespace
Modules: API
Constant Summary collapse
- METHOD_METHODS =
%i( source_location parameters arity name owner to_proc unbind )
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
Instance Method Summary collapse
-
#initialize(receiver) ⇒ LazyMethod
constructor
A new instance of LazyMethod.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(receiver) ⇒ LazyMethod
Returns a new instance of LazyMethod.
5 6 7 8 |
# File 'lib/lazy_method.rb', line 5 def initialize(receiver) @receiver = receiver @lazy_call_method = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object (private)
45 46 47 48 49 50 51 52 53 |
# File 'lib/lazy_method.rb', line 45 def method_missing(name, *) return unless respond_to_missing?(name, false) m = @receiver.__method__(name) if @lazy_call_method m.__send__ @lazy_call_method else m end end |
Instance Attribute Details
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
4 5 6 |
# File 'lib/lazy_method.rb', line 4 def receiver @receiver end |
Instance Method Details
#to_s ⇒ Object Also known as: inspect
29 30 31 |
# File 'lib/lazy_method.rb', line 29 def to_s "#<LazyMethod #{@receiver}#{@lazy_call_method ? "(#{@lazy_call_method})" : ''}>" end |