From: "David A. Black" Date: 2005-12-03T06:53:09+09:00 Subject: Re: Make a symbol represent a method? Hi -- On Sat, 3 Dec 2005, Jacob Fugal wrote: > On 12/2/05, Chris Irish wrote: >> K.... I get it >> One more thing, Can I use the symbol to call a method and pass arguments >> to it? Or is it just a reference to the methods name so that's not >> possible? > > Sure thing. The symbol is not a reference to the method at all. What > the symbol is is a *key* into the objects method table, the value > corresponding to that key is the reference to the Method object. I can > use a symbol (it'll "auto-vivify", for lack of a better word) even > without a corresponding method. True... though it's a bit like saying, "It's possible to create a string even if you don't use it as a hash key" :-) I'd put it more simply: a symbol is a built-in data type which can be, and is, used for many purposes both internally and in user-space. From the user side, I don't think there's any special relation between the symbol :x and a method called x. The use of one, in itself, never has any implications for the other. > As far as syntax for calling a method just using it's named symbol, > there are two ways you can do this. The first is to use send: [...] > An alternate technique is to grab an actual reference to the method > itself. This is available using the 'method' method: Neither of these actually requires a Symbol object, though (as opposed to a String). David -- David A. Black dblack@wobblini.net "Ruby for Rails", forthcoming from Manning Publications, April 2006!