Parent

Methods

UnboundMethod

Public Instance Methods

arguments() click to toggle source

Resolves the arguments of the method to have an identical signiture —useful for preserving arity.

  class X
    def foo(a, b); end
    def bar(a, b=1); end
  end

  foo_method = X.instance_method(:foo)
  foo_method.arguments   #=> "a0, a1"

  bar_method = X.instance_method(:bar)
  bar_method.arguments   #=> "a0, *args"

When defaults are used the arguments must end in “*args”.

CREDIT: Trans

    # File lib/core/facets/unboundmethod/arguments.rb, line 21
21:   def arguments
22:     ar = arity
23:     case ar <=> 0
24:     when 1
25:       args = []
26:       ar.times do |i|
27:         args << "a#{i}"
28:       end
29:       args = args.join(", ")
30:     when 0
31:       args = ""
32:     else
33:       ar = -ar - 1
34:       args = []
35:       ar.times do |i|
36:         args << "a#{i}"
37:       end
38:       args << "*args"
39:       args = args.join(", ")
40:     end
41:     return args
42:   end
name() click to toggle source

Return the name of the method.

Be aware that in ruby 1.9 UnboundMethod#name is defined already, but it returns a Symbol not a String.

  class X
    def foo; end
  end

  meth = X.instance_method(:foo)

  meth.name  #=> :foo

CREDIT: Trans

    # File lib/core/facets/unboundmethod/name.rb, line 20
20:     def name
21:       i = to_s.rindex('#')
22:       to_s.slice(i+1...1).to_sym
23:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.