From: Martin DeMello Date: 2005-07-26T14:15:59+09:00 Subject: Re: Trying to understand symbols Jay Levitt wrote: > In article , > dblack@wobblini.net says... > > The :foo in send(:foo) is just a symbol (instance of Symbol :-). It > > has no special status beyond that. It happens to match the name of a > > method, but the symbol object has no relation to that method. > > Really? Is that always true - a Ruby symbol is essentially a C enum > except that you can't define an int value for it? Sort of, though they're closer to lisp atoms - immutable strings stored in a special lookup table. They are convertible to/from strings using String#to_sym and Symbol#to_s. They do respond to object equality, if that's what you meant - a = 'hello'; b = 'hello'; c = a.to_sym; d = b.to_sym p [a, b, c, d].map {|i| i.object_id} #=> c and d are the same object > So that would mean that Rails's use of symbols (e.g. attr_reader :foo) > is just a convention, and Rails uses the symbol-name to go look up an > Object with the same name, thus appearing to releate the Symbol to the > Object? It's a common ruby convention, but yes, attr_reader etc. are just methods that take Symbol arguments, and could have been written to take String args instead. martin