I just realized that none of the other answers touch the most trivial aspect of the question: why the #
sign?
I have two theories:
- It might come from Smalltalk, where symbols are written
#sym
(instead of :sym
) as they are in Ruby. So, if you want to refer to a Method object (as opposed to calling a method), then you would call something like Array >> #new.
(The >>
is itself a method that returns the method passed to it. So, in Ruby that would be Array.method :new
.) In Smalltalk documentation, methods are generally referred to as Class>>method
, but in Ruby Class:method
would have made more sense, except that it is easily confused with Class::method
. Therefore, Class#method
was chosen.
- My other theory is that it simply was chosen because
#
is the comment character in Ruby.
A definitive answer can only be given by whoever invented that convention. If it was invented for the Programming Ruby book, that would be either Dave Thomas or Andy Hunt, but I kind of doubt that. The book came out in 2001, Ruby started in 1993, how were they referring to methods before then?