Method: MethodArgs::Processor#process_args

Defined in:
lib/method_args/processor.rb

#process_args(exp) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/method_args/processor.rb', line 56

def process_args(exp)
  exp.shift
  arg_list = Args.new(@current_class.clone)
  while !exp.empty?
    t = exp.shift
    case t
    when Symbol
      arg_list << case t.to_s[0]
      when ?* then Args::Arg.new(t.to_s[1, t.to_s.size].to_sym, :splat)
      when ?& then Args::Arg.new(t.to_s[1, t.to_s.size].to_sym, :block)
      else         Args::Arg.new(t, :required)
      end
    when Sexp
      case t.shift
      when :block
        lasgn = t.shift
        lasgn.shift
        name = lasgn.shift
        new_arg = Args::Arg.new(name, :optional, @ruby2ruby.process(lasgn.last))
        arg_list.each_with_index{|arg, idx| arg_list[idx] = new_arg if arg.name == name}
      end
    end
  end
  @methods[current_classname] << [@current_method, arg_list]
  exp
end