Sha256: 76c0bc7acaac77d1608fad3c8a2d7959d0c257ac56c743d6d70e97838f34d147

Contents?: true

Size: 852 Bytes

Versions: 2

Compression:

Stored size: 852 Bytes

Contents

require 'sourcify'
require 'sorcerer'

module Source_cleaner
 private

  #cleans up the string for further processing and separates arguments from body
  def block2source(method_name, &block)
    source = block.to_sexp
    raise 'unknown format' unless source[0] == :iter or source.length != 4
    args = get_args source[2]
    body = source[3]
    return args, body
  end

  def get_args(sexp)
    return nil unless sexp
    return sexp[1] if sexp[0] == :lasgn
    sexp = sexp[1][1..-1] # array or arguments
    args = []
    sexp.each { |e|
      args << e[1]
    }
    args.join(',')
  end

 def lambda2method (method_name, method)
    arguments, body  = method.arguments, method.body
    transform_ast body
    block = Ruby2Ruby.new.process(body)
    args = "(#{arguments})" if arguments
    "\ndef #{method_name} #{args}\n#{block} end\n"
 end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
maroon-0.6.1 lib/Source_cleaner.rb
maroon-0.6.0 lib/Source_cleaner.rb