0

I've just learned the difference between Array.push(*more_than_one) vs Array << just_one) but confused by the poster using Class#Method in his comments and Class.method in the code snippet (link 1 below).

I've read the post about Java # vs . in responses (link 2 below), but didn't catch the relevance to the HTML part.

I'm learning Ruby (before rails) and am from a C# .NetCF background (little lol at the # here) and could really do with some help as to why the notation differs between comments and code snippets ?

link 1 Ruby - Difference between Array#<< and Array#push

link 2 Why do some folks use Class#method instead of Class.method in correspondence?

Community
  • 1
  • 1

2 Answers2

2

It's just a convention used to distinguish between class/module methods and instance methods when writing about Ruby code.

You'll see Foo::bar to denote class/module methods and Foo#bar for instance methods.

See this question and its answers for some insight into the history of the different symbols.

Community
  • 1
  • 1
pdoherty926
  • 9,895
  • 4
  • 37
  • 68
0

In short, it's only a Ruby Documentation convention.

Foo#bar for class Foo's instance method bar, and you should call it like Foo.new.bar in your code.

Foo::bar for class Foo's class method bar, and you should call it like Foo.bar in your code.

Aetherus
  • 8,720
  • 1
  • 22
  • 36