From: Sebastian Hungerecker Date: 2009-01-05T21:31:53+09:00 Subject: Re: VERY simple question about "?" Tom Cloyd wrote: > <=> == === != =~ !~ > > There's some very strange stuff there. I'm only certain about the > function of ONE of these As has already been mentionen, they are methods and do whatever they're defined to do. That being said here's what their intended function is: <=> should be defined by any class that includes the Comaparable module. It should return -1,0 or 1 depending on whether the receiver (the lhs) is less than, equal to or greater than the argument (the rhs). == should return true if (and only if) the lhs is equal to the rhs (where the definition of equality depends on the class). Object#== is defined to return true if two objects are actually the same object (i.e. both the receiver and the argument are actually references to the same location in memory). === defines when an object "matches" another object in a case-when-statement (or the grep method). For example in the following code, the puts will be executed if y === x is true: case x when y puts "tada" end Object#=== is defined to return the same as ==, Regexp#=== is defined to return true if the regexp matches a string and Range#=== is defined to return true if a given object is inside the range. != is simply the negation of ==, so x != y is equivalent to !(x == y) Regexp#=~, which takes a string as an argument, and String#=~, which takes a regex as an argument, return the index where the regex matches the string or nil if the regex does not match the string. All of those are documented in the API docs btw. HTH, Sebastian -- Jabber: sepp2k@jabber.org ICQ: 205544826