Class: Method

Inherits:
Object show all
Defined in:
eval.c

Instance Method Summary collapse

Instance Method Details

#==(other_meth) ⇒ Boolean

Two method objects are equal if that are bound to the same object and contain the same body.

Returns:

  • (Boolean)


9279
9280
9281
# File 'eval.c', line 9279

static VALUE
method_eq(method, other)
VALUE method, other;

#call(args, ...) ⇒ Object #[](args, ...) ⇒ Object

Invokes the meth with the specified arguments, returning the method’s return value.

m = 12.method("+")
m.call(3)    #=> 15
m.call(20)   #=> 32

Overloads:



9511
9512
9513
# File 'eval.c', line 9511

static VALUE
method_call(argc, argv, method)
int argc;

#arityFixnum

Returns an indication of the number of arguments accepted by a method. Returns a nonnegative integer for methods that take a fixed number of arguments. For Ruby methods that take a variable number of arguments, returns -n-1, where n is the number of required arguments. For methods written in C, returns -1 if the call takes a variable number of arguments.

class C
  def one;    end
  def two(a); end
  def three(*a);  end
  def four(a, b); end
  def five(a, b, *c);    end
  def six(a, b, *c, &d); end
end
c = C.new
c.method(:one).arity     #=> 0
c.method(:two).arity     #=> 1
c.method(:three).arity   #=> -1
c.method(:four).arity    #=> 2
c.method(:five).arity    #=> -3
c.method(:six).arity     #=> -3

"cat".method(:size).arity      #=> 0
"cat".method(:replace).arity   #=> 1
"cat".method(:squeeze).arity   #=> -1
"cat".method(:count).arity     #=> -1

Returns:



9695
9696
9697
# File 'eval.c', line 9695

static VALUE
method_arity(method)
VALUE method;

#call(args, ...) ⇒ Object #[](args, ...) ⇒ Object

Invokes the meth with the specified arguments, returning the method’s return value.

m = 12.method("+")
m.call(3)    #=> 15
m.call(20)   #=> 32

Overloads:



9511
9512
9513
# File 'eval.c', line 9511

static VALUE
method_call(argc, argv, method)
int argc;

#cloneObject

MISSING: documentation



9460
9461
9462
# File 'eval.c', line 9460

static VALUE
method_clone(self)
VALUE self;

#to_sString #inspectString

Show the name of the underlying method.

"cat".method(:count).inspect   #=> "#<Method: String#count>"

Overloads:



9744
9745
9746
# File 'eval.c', line 9744

static VALUE
method_inspect(method)
VALUE method;

#nameString

Returns the name of the method.

Returns:



9353
9354
9355
# File 'eval.c', line 9353

static VALUE
method_name(obj)
VALUE obj;

#ownerObject

Returns the class or module that defines the method.



9370
9371
9372
# File 'eval.c', line 9370

static VALUE
method_owner(obj)
VALUE obj;

#receiverObject

Returns the bound receiver of the method object.

Returns:



9336
9337
9338
# File 'eval.c', line 9336

static VALUE
method_receiver(obj)
VALUE obj;

#to_procProc

Returns a Proc object corresponding to this method.

Returns:



9842
9843
9844
# File 'eval.c', line 9842

static VALUE
method_proc(method)
VALUE method;

#to_sString #inspectString

Show the name of the underlying method.

"cat".method(:count).inspect   #=> "#<Method: String#count>"

Overloads:



9744
9745
9746
# File 'eval.c', line 9744

static VALUE
method_inspect(method)
VALUE method;

#unbindObject

Dissociates meth from it’s current receiver. The resulting UnboundMethod can subsequently be bound to a new object of the same class (see UnboundMethod).



9309
9310
9311
# File 'eval.c', line 9309

static VALUE
method_unbind(obj)
VALUE obj;