Hi, all
I try to use comparision operator as a symbol type.
but, I met the following problems.
Here is my example.
irb(main):001:0> a = 1
=> 1
irb(main):002:0> a.send(:==, 1)
=> true
irb(main):003:0> a.send(:==, 2)
=> false
irb(main):004:0> a.send(:>, 0)
=> true
irb(main):005:0> a.send(:>, 2)
=> false
irb(main):006:0> a.send(:!=, 2)
SyntaxError: compile error
(irb):6: syntax error, unexpected tNEQ, expecting tSTRING_CONTENT or
tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
a.send(:!=, 2)
^
from (irb):6
from :0
irb(main):007:0> a.send(’==’, 2)
=> false
irb(main):008:0> a.send(’!=’, 2)
NoMethodError: undefined method !=' for 1:Fixnum from (irb):8:in
send’
from (irb):8
from :0
irb(main):009:0>
Is any idea?
On Dec 28, 2008, at 22:58 , Jun Y. Kim wrote:
irb(main):008:0> a.send(’!=’, 2)
NoMethodError: undefined method !=' for 1:Fixnum from (irb):8:in
send’
from (irb):8
from :0
there is no ‘!=’ method, there is only ‘==’. you should send ‘==’ and
not/! the result:
! a.send(’==’, 2)
Hi.
AFAIK, != gets converted by Ruby when your program is read. For example,
foo
!= bar becomes !(foo == bar).
Regards,
Yaser S.
irb(main):006:0> a.send(:!=, 2)
SyntaxError: compile error
(irb):6: syntax error, unexpected tNEQ, expecting tSTRING_CONTENT or
tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
a.send(:!=, 2)
^
from (irb):6
from :0
As you see, ruby can recognize a != as a tNEG(not equals).
so , I convinced a method is existed for this type of a comparison.
I have to use a workaround way, ;-<
-
- 29, 오후 4:54, Ryan D. 작성:
On Dec 29, 2008, at 04:16 , David A. Black wrote:
from (irb):8
ruby 1.9.1 (2008-12-14 revision 20738) [i386-darwin9.5.0]
true
that’s a bug, == and != shouldn’t be able to disagree:
class X; def == o; :great; end; def != o; :horrible; end; end
=> nil
x = X.new
=> #<X:0x419948>
x == 0
=> :great
x != 0
=> :horrible
Hi –
On Mon, 29 Dec 2008, Ryan D. wrote:
the result:
! a.send(’==’, 2)
In 1.9 != becomes a method:
$ ruby19 -ve ‘p 1.send("!=", 2)’
ruby 1.9.1 (2008-12-14 revision 20738) [i386-darwin9.5.0]
true
David
On Dec 29, 2008, at 00:17 , Jun Y. Kim wrote:
irb(main):006:0> a.send(:!=, 2)
SyntaxError: compile error
(irb):6: syntax error, unexpected tNEQ, expecting tSTRING_CONTENT or
tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
a.send(:!=, 2)
^
from (irb):6
from :0
As you see, ruby can recognize a != as a tNEG(not equals).
no. you’re getting a syntax error because :!= is not a valid symbol,
but :"!=" is. Try that and you’ll see that there is no such method.
Hi, Ryan
This is still unavailable way on version 1.8.7.
According to previous responses, I think the way to use what I want is
just to update ruby’s version :).
-
- 30, ¿ÀÀü 9:37, Ryan D. ÀÛ¼º:
Hi, David.
This is a really good news for me
but, the only option I can take is just a version 1.8.7 ;-<
anyway, thank you~
-
- 29, ¿ÀÈÄ 9:16, David A. Black ÀÛ¼º: