Module: GetArgs

Included in:
Method, UnboundMethod
Defined in:
lib/airbrush/core_ext/get_args.rb

Overview

Used in mapping controller arguments to the params hash. NOTE: You must have the ‘ruby2ruby’ gem installed for this to work.

Examples

# In PostsController
def show(id)  #=> id is the same as params[:id]

Instance Method Summary collapse

Instance Method Details

#get_argsObject

Returns

Array

Method arguments and their default values.

Examples

class Example
  def hello(one,two="two",three)
  end

  def goodbye
  end
end

Example.instance_method(:hello).get_args
  #=> [[:one], [:two, "two"], [:three, "three"]]
Example.instance_method(:goodbye).get_args  #=> nil


80
81
82
83
84
85
# File 'lib/airbrush/core_ext/get_args.rb', line 80

def get_args
  klass, meth = self.to_s.split(/ /).to_a[1][0..-2].split("#")
  # Remove stupidity for #<Method: Class(Object)#foo>
  klass = $` if klass =~ /\(/
  ParseTreeArray.translate(Object.const_get(klass), meth).get_args
end