Sha256: dc1b9243e44e2ef7576fd74fdd71292cb55e5877a18132c7221c55aca570a6ad

Contents?: true

Size: 714 Bytes

Versions: 5

Compression:

Stored size: 714 Bytes

Contents

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

module MethodAsCode
  def as_code(indent=0, name=nil)
    sig = self.signature
    if self.body.respond_to?(:body) then
      # YARV
      body_expression = self.body.body.as_code(indent+1)
    else
      # pre-YARV
      body_expression = self.body ? self.body.as_code(indent+1) : ''
    end
    name ||= sig.name
    s = "#{'  '*indent}def #{name}(#{sig.param_list})\n"
    if body_expression then
      s += "#{body_expression}\n"
    end
    s += "#{'  '*indent}end"
    return s
  end
end

class Method
  include MethodAsCode
end

class UnboundMethod
  include MethodAsCode
end

Version data entries

5 entries across 5 versions & 1 rubygems

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