Method: Innate::Node#find_method

Defined in:
lib/innate/node.rb

#find_method(name, params) ⇒ String, Symbol

TODO:

Once 1.9 is mainstream we can use Method#parameters to do accurate prediction

We check arity if possible, but will happily dispatch to any method that has default parameters. If you don’t want your method to be responsible for messing up a request you should think twice about the arguments you specify due to limitations in Ruby.

So if you want your method to take only one parameter which may have a default value following will work fine:

def index(foo = "bar", *rest)

But following will respond to /arg1/arg2 and then fail due to ArgumentError:

def index(foo = "bar")

Here a glance at how parameters are expressed in arity:

def index(a)                  # => 1
def index(a = :a)             # => -1
def index(a, *r)              # => -2
def index(a = :a, *r)         # => -1

def index(a, b)               # => 2
def index(a, b, *r)           # => -3
def index(a, b = :b)          # => -2
def index(a, b = :b, *r)      # => -2

def index(a = :a, b = :b)     # => -1
def index(a = :a, b = :b, *r) # => -1

Parameters:

  • name (String, Symbol)
  • params (Array)

Returns:

  • (String, Symbol)

See Also:

Author:

  • manveru



512
513
514
515
# File 'lib/innate/node.rb', line 512

def find_method(name, params)
  return unless arity = method_arities[name.to_s]
  name if arity == params.size || arity < 0
end