[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

inequality test

Junyoung Kim

12/20/2008 6:10:00 AM

Hi, all

I have tested comparison test by using object concept.

I mean this one

a = 1

a.send('==', 1)
=> true

a.send('>', 0)
==>true

a.send('<', -1)
==> false

With this concept, however, I cannot test inequlity test('!=').

Whenever I try to this test, I met the following error.

irb(main):001:0> a = 1
=> 1
irb(main):002:0> a.send('!=', 0)
NoMethodError: undefined method `!=' for 1:Fixnum
from (irb):2:in `send'
from (irb):2
from :0
irb(main):003:0>

Any idea for this?
1 Answer

Mikael Høilund

12/20/2008 6:18:00 AM

0

On Dec 20, 2008, at 07:07, juneng wrote:
> irb(main):002:0> a.send('!=3D', 0)
> NoMethodError: undefined method `!=3D' for 1:Fixnum
> from (irb):2:in `send'
> from (irb):2
> from :0

!=3D is purely syntactical sugar for !(foo =3D=3D bar). If you send '=3D=3D=
' and =20
negate the result, that'll give you what you want. You can't define =20
the !=3D method, and you can't make it mean anything other than =93the =20=

negation of =3D=3D.=94

--=20
Name =3D "Mikael H=F8ilund"; Email =3D Name.gsub %r/\s/,%#=3D?,#
*a=3De=3D?=3D,!????,:??,?,,Email.downcase![eval(%["\\%o\\%o"]%
[?**2+?o,?\\*2])]=3D"o";Email.gsub! %%\%c%*3%a, %?%c? % ?@
def The(s)%%\%s.%%s+%.org\n.end; :Go and print The Email