Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Ruby Programming
Previous Page Home Next Page
class Method
Parent: Object
Version: 1.6

Index:

[ ] arity call to_proc


Method objects are created by Object#method , and are associated with a particular object (not just with a class). They may be used to invoke the method within the object, and as a block associated with an iterator.

class Thing
  def square(n)
    n*n
  end
end
aThing  = Thing.new
aMethod = aThing.method("square")
aMethod.call(9) 81
[ 1, 2, 3 ].collect(&aMethod) [1, 4, 9]

instance methods
[ ] meth[ [ args ]* ] -> anObject

Synonym for Method.call.

arity meth.arity -> aFixnum

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.

call meth.call( [ args ]* ) -> anObject

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

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

to_proc meth.to_proc -> aProc

Returns a Proc object corresponding to this method.


Ruby Programming
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire