Class: Method
Instance Method Summary collapse
-
#==(other_meth) ⇒ Boolean
Two method objects are equal if that are bound to the same object and contain the same body.
-
#[] ⇒ Object
Invokes the meth with the specified arguments, returning the method’s return value.
-
#arity ⇒ Fixnum
Returns an indication of the number of arguments accepted by a method.
-
#call ⇒ Object
Invokes the meth with the specified arguments, returning the method’s return value.
-
#clone ⇒ Object
MISSING: documentation.
-
#inspect ⇒ Object
Show the name of the underlying method.
-
#to_proc ⇒ Proc
Returns a
Proc
object corresponding to this method. -
#to_s ⇒ Object
Show the name of the underlying method.
-
#unbind ⇒ Object
Dissociates meth from it’s current receiver.
Instance Method Details
#==(other_meth) ⇒ Boolean
Two method objects are equal if that are bound to the same object and contain the same body.
9017 9018 9019 |
# File 'eval.c', line 9017 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
9175 9176 9177 |
# File 'eval.c', line 9175 static VALUE method_call(argc, argv, method) int argc; |
#arity ⇒ Fixnum
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
9359 9360 9361 |
# File 'eval.c', line 9359 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
9175 9176 9177 |
# File 'eval.c', line 9175 static VALUE method_call(argc, argv, method) int argc; |
#clone ⇒ Object
MISSING: documentation
9147 9148 9149 |
# File 'eval.c', line 9147 static VALUE method_clone(self) VALUE self; |
#to_s ⇒ String #inspect ⇒ String
Show the name of the underlying method.
"cat".method(:count).inspect #=> "#<Method: String#count>"
9408 9409 9410 |
# File 'eval.c', line 9408 static VALUE method_inspect(method) VALUE method; |
#to_proc ⇒ Proc
Returns a Proc
object corresponding to this method.
9505 9506 9507 |
# File 'eval.c', line 9505 static VALUE method_proc(method) VALUE method; |
#to_s ⇒ String #inspect ⇒ String
Show the name of the underlying method.
"cat".method(:count).inspect #=> "#<Method: String#count>"
9408 9409 9410 |
# File 'eval.c', line 9408 static VALUE method_inspect(method) VALUE method; |
#unbind ⇒ Object
Dissociates meth from it’s current receiver. The resulting UnboundMethod
can subsequently be bound to a new object of the same class (see UnboundMethod
).
9047 9048 9049 |
# File 'eval.c', line 9047 static VALUE method_unbind(obj) VALUE obj; |