Class: Jsapi::Meta::Callable::SymbolEvaluator
- Inherits:
-
Object
- Object
- Jsapi::Meta::Callable::SymbolEvaluator
- Defined in:
- lib/jsapi/meta/callable/symbol_evaluator.rb
Instance Attribute Summary collapse
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
-
#call(object) ⇒ Object
Evaluates the symbol within the context of
object. -
#initialize(symbol) ⇒ SymbolEvaluator
constructor
A new instance of SymbolEvaluator.
-
#inspect ⇒ Object
:nodoc:.
Constructor Details
#initialize(symbol) ⇒ SymbolEvaluator
9 10 11 12 |
# File 'lib/jsapi/meta/callable/symbol_evaluator.rb', line 9 def initialize(symbol) @symbol = symbol @keys = [@symbol, @symbol.to_s] end |
Instance Attribute Details
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
7 8 9 |
# File 'lib/jsapi/meta/callable/symbol_evaluator.rb', line 7 def symbol @symbol end |
Instance Method Details
#call(object) ⇒ Object
Evaluates the symbol within the context of object.
19 20 21 22 23 24 25 26 |
# File 'lib/jsapi/meta/callable/symbol_evaluator.rb', line 19 def call(object) if object.respond_to?(@symbol) object.public_send(@symbol) elsif object.respond_to?(:[]) && object.respond_to?(:key?) @keys.each { |key| return object[key] if object.key?(key) } nil end end |
#inspect ⇒ Object
:nodoc:
14 15 16 |
# File 'lib/jsapi/meta/callable/symbol_evaluator.rb', line 14 def inspect # :nodoc: "#<#{self.class.name} #{@symbol.inspect}>" end |