From: Brian Candler Date: 2009-08-25T21:51:31+09:00 Subject: Re: operators vs. methods 7stud -- wrote: >>> So, where might I find a list of the special sugary methods? >> >> There is a list in the printed edition of the Pickaxe IIRC. >> > > Ah, yes. p. 339 (pickaxe2). The ones with check marks preceding them > in the operator table. > > In order of precedence(highest at the top): > > [] []= > ** > ! ~ + - (unary plus and minus, e.g. -1) > * / % > + - >>> << > & > ^ | > <= < > >= > <=> == === != =~ !~ Note that the majority of these call a method whose symbolic name is the same as the operator itself, but there are some exceptions: (1) unary plus and unary minus are :+@ and :-@ >> 3.send(:-@) => -3 (2) !~ and != operators do not map directly to method calls, but call :=~ and :== and negate the answers >> class Foo; def ==(bar); puts "== #{bar}"; end; end => nil >> Foo.new == "x" == x => nil >> Foo.new != "x" == x => true I have written programs which use x.send(:[]=, val). I call this smiley programming :-@ -- Posted via http://www.ruby-forum.com/.