0

I'm new to Rails and I'm studying Redmine. I see 2 magic function definitions as below:

1.

  def to_s; name end

and 2.

  def <=>(tracker)
    position <=> tracker.position
  end

I cannot understand, please explain what is ";" in "to_s;" and what is "<=>"

Thank you

vietstone
  • 8,784
  • 16
  • 52
  • 79
  • 1
    btw, 1 has no magic, its just a method written on one line, and `;` is used as separator – apneadiving Aug 11 '14 at 12:23
  • Hint: `def foo` defines a method named `foo`. `def bar` defines a method named `bar`. `def <=>` defines a method named … can you guess? – Jörg W Mittag Aug 11 '14 at 15:51
  • `<=>` is the comparison operator for performing sorts. If you have a collection of these and call sort it will use this method to compare the two objects. – CWitty Aug 11 '14 at 17:33

0 Answers0