Class: Sablon::Expression::LookupOrMethodCall

Inherits:
Struct
  • Object
show all
Defined in:
lib/sablon/operations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expressionObject

Returns the value of attribute expression

Returns:

  • (Object)

    the current value of expression



167
168
169
# File 'lib/sablon/operations.rb', line 167

def expression
  @expression
end

#receiver_exprObject

Returns the value of attribute receiver_expr

Returns:

  • (Object)

    the current value of receiver_expr



167
168
169
# File 'lib/sablon/operations.rb', line 167

def receiver_expr
  @receiver_expr
end

Instance Method Details

#evaluate(context) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/sablon/operations.rb', line 168

def evaluate(context)
  if receiver = receiver_expr.evaluate(context)
    expression.split(".").inject(receiver) do |local, m|
      case local
      when Hash
        local[m]
      else
        local.public_send m if local.respond_to?(m)
      end
    end
  end
end

#inspectObject



181
182
183
# File 'lib/sablon/operations.rb', line 181

def inspect
  "«#{receiver_expr.name}.#{expression}»"
end