### Home Classes Methods

### In Files

- lib/facets/unboundmethod/arguments.rb
- lib/facets/unboundmethod/name.rb

### Parent

Object

### Methods

- #arguments
- #name

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Lazy
- Lazy::Future
- Lazy::Promise
- Lazy::Promise::DIVERGES
- Lazy::PromiseSafe
- Enumerable
- Enumerable::Recursor
- Method
- Method::Composition
- Module
- Module::InstanceFunction
- Array
- Binding
- Class
- Comparable
- Denumerable
- Denumerator
- Dir
- Enumerator
- Exception
- Facets
- FalseClass
- File
- FileTest
- Fixnum
- Float
- Functor
- Hash
- Indexable
- Instance
- Integer
- Kernel
- MatchData
- NA
- NilClass
- Numeric
- Object
- ObjectSpace
- Proc
- Process
- Range
- Regexp
- String
- Struct
- Symbol
- Time
- TrueClass
- UnboundMethod

No matching classes.

# 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/facets/unboundmethod/arguments.rb, line 21
    def arguments
      ar = arity
      case ar <=> 0
      when 1
        args = []
        ar.times do |i|
          args << "a#{i}"
        end
        args = args.join(", ")
      when 0
        args = ""
      else
        ar = -ar - 1
        args = []
        ar.times do |i|
          args << "a#{i}"
        end
        args << "*args"
        args = args.join(", ")
      end
      return args
    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 NameExample
      def foo; end
    end

    meth = NameExample.instance_method(:foo)

    meth.name.to_sym  #=> :foo

CREDIT: Trans

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.