Sha256: 3a0eca8228e41ac75df8fd29bed17a12d4619d580da1bd87bc8d1e7c78999a71

Contents?: true

Size: 860 Bytes

Versions: 5

Compression:

Stored size: 860 Bytes

Contents

require 'internal/node/as_expression'
require 'internal/vm/iseq/as_expression'
require 'internal/method/signature'
require 'internal/method'

module MethodAsExpression
  # 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.
  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
end

class Method
  include MethodAsExpression
end

class UnboundMethod
  include MethodAsExpression
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-internal-0.7.3 lib/internal/method/as_expression.rb
ruby-internal-0.7.2 lib/internal/method/as_expression.rb
ruby-internal-0.7.1 lib/internal/method/as_expression.rb
ruby-internal-0.7.0 lib/internal/method/as_expression.rb
ruby-internal-0.6.0 lib/internal/method/as_expression.rb