Class: Greased::MethodCaller

Inherits:
Object
  • Object
show all
Defined in:
lib/greased/method_caller.rb

Instance Method Summary collapse

Constructor Details

#initialize(operator = nil, options = {}) ⇒ MethodCaller

Returns a new instance of MethodCaller.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/greased/method_caller.rb', line 4

def initialize(operator = nil, options = {})
  @operator = operator
  @evaluations = []
  
  if @operator.nil?
    @evaluations << :default              
  elsif @operator == "="
    @evaluations << :assign
  else
    @evaluations << :evaluate
  end
  
  if options[:reassign]
    @evaluations << :assign
  end
end

Instance Method Details

#call(target, name, value) ⇒ Object



21
22
23
24
25
# File 'lib/greased/method_caller.rb', line 21

def call(target, name, value)
  @evaluations.inject(value) do |result, evaluator|
    send(evaluator, target, name, result)
  end
end