From: "月忧茗" Date: 2012-10-27T23:30:22+09:00 Subject: Re: Newbie, questions about === expression --f46d042f94864eedcf04cd0b462f Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Oh, Maybe I found the reason: irb(main):195:0> (1..10) =3D=3D=3D 1 =3D> true 2012/10/27 =E6=9C=88=E5=BF=A7=E8=8C=97 > Hi, > > I'm learning ruby this days. > And I followed this docs: http://www.ruby-doc.org/docs/ProgrammingRuby/ > > > Now, I have some questions about =3D=3D=3D expression > > > irb(main):138:0> case 1 > irb(main):139:1> when 1..10 then 'in' > irb(main):140:1> else 'not in' > irb(main):141:1> end > > obviously, the result is 'in' > > In the docs, there are an explanation: > *case operates by comparing the target (the expression after the keyword > case) with each of the comparison expressions after the when keywords. > This test is done using comparison =3D=3D=3D target. As long as a class d= efines > meaningful semantics for =3D=3D=3D (and all the built-in classes do), obj= ects > of that class can be used in case expressions. * > > > But, when I type this, why throw an error ? > > irb(main):149:0> 1..10 =3D=3D=3D 1 > ArgumentError: bad value for range > from (irb):149 > from /opt/ruby-1.9.3/bin/irb:12:in `
' > > > > Thanks. > --f46d042f94864eedcf04cd0b462f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Oh,=C2=A0 Maybe I found the reason:

irb(main):195:0> (1..10) = =3D=3D=3D 1
=3D> true




2= 012/10/27 =E6=9C=88=E5=BF=A7=E8=8C=97 <yueyoum@gmail.com>
Hi,

I'm learning ruby this days.=
And I followed this docs:=C2=A0 http://www.ruby-doc.org/docs/Programmi= ngRuby/


Now, I have some questions about =3D=3D=3D=C2=A0 expression


irb(main):138:0> case 1
irb(main):139:1> when 1..10 then &= #39;in'
irb(main):140:1> else 'not in'
irb(main):141:1= > end

obviously, the result is 'in'

In the docs, t= here are an explanation:=C2=A0
case operates by comparing the target (the expression after= the keyword case) with each of the comparison expressions after th= e when keywords. This test is done using comparison=C2=A0=3D=3D=3D=C2=A0target.=20 As long as a class defines meaningful semantics for =3D=3D=3D (and all the built-in class= es do), objects of that class can be used in case expressions.


But,=C2=A0 when I type this,=C2=A0 why throw an error ?
=
irb(main):149:0> 1..10 =3D=3D=3D 1
ArgumentError: bad value for r= ange
=C2=A0=C2=A0=C2=A0 from (irb):149
=C2=A0=C2=A0=C2=A0 from /opt/r= uby-1.9.3/bin/irb:12:in `<main>'



Thanks.

--f46d042f94864eedcf04cd0b462f--