From: Omran Nazir Date: 2009-11-19T07:01:09+09:00 Subject: Re: operators vs. methods --0-67021314-1258581291=:93712 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Err, Hi Sarah,=0A=0AWell i'm a newbie to fresh out of the womb in fact but = i think i can point you in the right direction. Firstly yes operators are i= mplemented as methods so 1+2 would be interpreted as 1.+(2) and since they = are methods there behavoiur for classes that you create can be specified by= you. Operators do also have a precedence as operators do in C and are meth= ods of all objects of the Numeric Class.=0A=0AFrom what I understand 'div' = and '/' and not exactly the same. So 1/2 would be seen as 1./(2) whereas if= you used 'div', you would write 1.div(2). The operator '/' seems to be equ= ipt to deal with spaces but not 'div', that is probaly why you would use '(= )' to pass the argument. You also have 'fdiv' for floating point division a= nd 'quo' returns a rational where possible.=0A=0AThis exact topic if covere= d in glorious technicolour in 'The Ruby Programming Language' by Flanagan a= nd Matsumoto, but I am sure you can google it also.=0A=0A Imran Nazir =0A= =0A=0AFriend, Boho, House Owner, Citizen, Engineer=0A=0A=0A=0A=0A=0A_______= _________________________=0AFrom: Sarah Allen =0ATo:= ruby-talk ML =0ASent: Tue, 25 August, 2009 8:06:2= 6=0ASubject: operators vs. methods=0A=0AToday I was just re-reading introdu= ctory Ruby docs as I prepare to teach=0Aa few newbies tomorrow and I find m= yself feeling newbie-ish.=0A=0AOn ruby-lang.org's Ruby from other languagag= e highlights=0Ahttp://www.ruby-lang.org/en/documentation/ruby-from-other-la= nguages/=0Ait points out that a method call is really a message to another = object:=0A=0A# This=0A1 + 2=0A# Is the same as this ...=0A1.+(2)=0A# Which = is the same as this:=0A1.send "+", 2=0A=0AThat's all well and good, except = that + isn't an ordinary method. If I=0Atake another method like div:=0A= =0A# This=0A4.div(2)=0A# Is not the same as=0A4 div 2=0A=0AIn fact the latt= er is a syntax error.=0A=0AWhen I first learned Ruby I was led to believe t= hat + is just a method=0Awith a funny name, but now that I think about it t= hat cannot be. Not=0Aonly is there a special way that spaces are handled, = but operator=0Aprecedence is pretty special too.=0A=0AWhere might I find th= is behavior documented? Is there a special list of=0Aoperators? How are t= hey different from methods? Can I create my own?=0A=0APuzzled, or maybe I = just need more sleep,=0A=0ASarah=0A-- =0APosted via http://www.ruby-forum.c= om/.=0A=0A=0A --0-67021314-1258581291=:93712--