Module: MethodAsExpression

Included in:
Method, UnboundMethod
Defined in:
lib/as_expression.rb

Instance Method Summary collapse

Instance Method Details

#as_expressionObject

It doesn’t entirely make sense to have Method#as_expression, because a method definition isn’t an expression. We have one anyway, to be consistent with Proc.



623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# File 'lib/as_expression.rb', line 623

def as_expression
  sig = self.signature
  if self.body.respond_to?(:body) then
    # YARV
    body_expression = self.body.body.as_expression
  else
    # pre-YARV
    body_expression = self.body.as_expression
  end
  if body_expression then
    return "def #{sig.name}(#{sig.param_list}); #{body_expression}; end"
  else
    return "def #{sig.name}(#{sig.param_list}); end"
  end
end