10

Possible Duplicate:
Why are methods in ruby documentation preceded by a pound sign?

EDIT: Duplicate of Why are methods in ruby documentation preceded by a pound sign?

Hi,

I'm trying to learn Ruby for fun at my spare time with the free Programming Ruby book. It is mostly fairly straight forward but I kept seeing notations like this KaraokeSong#to_s, which is not really explained in the earlier chapters of the book.

I know it meant <class>#<method> but it is something you can use in the code? or just a notation ruby programmers use to specifiy a method like <class>::<method> notation used by C++ programmers?

Community
  • 1
  • 1
oscarkuo
  • 10,431
  • 6
  • 49
  • 62
  • This is a duplicate of http://StackOverflow.Com/questions/736120/ . Interestingly, none of the answers to that question answer the most trivial aspect: why the # sign? – Jörg W Mittag Aug 22 '09 at 20:56

2 Answers2

39

# = instance method

:: = class method

Per ruby docs:

Use :: for describing class methods, # for describing instance methods, and use . for example code.

eho
  • 169
  • 1
  • 10
Andy Gaskell
  • 31,495
  • 6
  • 74
  • 83
1

From the rdoc docs:

Names of classes, source files, and any method names containing an underscore or preceded by a hash character are automatically hyperlinked from comment text to their description.

BTW, I asked the same question some time ago :-)

Ed S.
  • 122,712
  • 22
  • 185
  • 265
  • really? I did browse through the list of suggestions before I ask the question. Anyway, so does it mean its just used for rdoc to generate document? So you can't really use class#method to say get the reference to a method object using this notation? – oscarkuo Aug 22 '09 at 20:22
  • Yeah, it's not always easy to find stuff around here. – Ed S. Aug 22 '09 at 21:05