Class: ActiveEnumerable::MethodCaller
- Inherits:
-
Object
- Object
- ActiveEnumerable::MethodCaller
- Defined in:
- lib/active_enumerable/method_caller.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#raise_no_method ⇒ Object
readonly
Returns the value of attribute raise_no_method.
Instance Method Summary collapse
- #call(method) ⇒ Object
-
#initialize(object, raise_no_method: true) ⇒ MethodCaller
constructor
A new instance of MethodCaller.
Constructor Details
#initialize(object, raise_no_method: true) ⇒ MethodCaller
Returns a new instance of MethodCaller.
6 7 8 9 |
# File 'lib/active_enumerable/method_caller.rb', line 6 def initialize(object, raise_no_method: true) @object = object @raise_no_method = raise_no_method end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
4 5 6 |
# File 'lib/active_enumerable/method_caller.rb', line 4 def object @object end |
#raise_no_method ⇒ Object (readonly)
Returns the value of attribute raise_no_method.
4 5 6 |
# File 'lib/active_enumerable/method_caller.rb', line 4 def raise_no_method @raise_no_method end |
Instance Method Details
#call(method) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/active_enumerable/method_caller.rb', line 11 def call(method) if object.is_a? Hash object.fetch(method) else object.public_send(method) end rescue NoMethodError => e raise e if raise_no_method rescue KeyError => e raise e, "#{e.message} for #{object}" if raise_no_method end |