Sha256: cdba2efcde606f815f9f1f86e010a91d03434b7b6845e4c2a3207a14dc8e9ff0

Contents?: true

Size: 827 Bytes

Versions: 2

Compression:

Stored size: 827 Bytes

Contents

require 'internal/method'

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

module MethodAsExpression
  # Return a single-line string representation of a method
  # TODO: this method would be more aptly named "as_expression_string".
  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

2 entries across 2 versions & 1 rubygems

Version Path
ruby-decompiler-0.0.3 lib/decompiler/method/as_expression.rb
ruby-decompiler-0.0.2 lib/decompiler/method/as_expression.rb