From: Brian Candler Date: 2009-01-05T18:58:12+09:00 Subject: Re: VERY simple question about "?" Tom Cloyd wrote: > * Operators - has the same problem as Thomas' book: precedence is shown, > but basic operator function appears to be assumed to be known. I'm > sorry, but I wasn't born with that knowledge. Look at this line: <=> == > === != =~ !~ There aren't really any operators in Ruby. Ruby simply maps all these to method calls (*), so to find out what the operator *means* you have to look at the class documentation for that method. e.g. str1 = "foo" str2 = "bar" p str1 <=> str2 Here you need to look at the documentation for String#<=> to see what it means. Yes, "<=>" is a legitimate method name :-) You can also call it like this: str1.<=>(str2) The only real purpose of the operator precedence table is to show how expressions containing multiple operators are resolved. e.g. 1 + 2 * 3 # same as: # 1 + (2 * 3) # same as: # 1.+(2.*(3)) Note that even the methods '+' and '*' do not necessarily have anything to do with addition or multiplication. It's entirely dependent on the target object how it implements these methods. For example: "123" * 3 # => "123123123" HTH, Brian. (*) The exceptions in ruby 1.8 are != and !~, which invoke the methods == and =~ but then negate the result -- Posted via http://www.ruby-forum.com/.