Why does "A".send('!='.to_sym, "B")
raises a NoMethodError in Ruby 1.8.7 while "A" != "B"
does not - and how would the correct syntax for Object.send
look like?
为什么“A”.send(“! =”。to_sym,“B”)在Ruby 1.8.7中引发一个NoMethodError,而“a”!发送看起来像什么?
2 个解决方案
#1
5
!=
isn't a method in ruby 1.8 It's hardwired to be the negation of calling ==
!=不是ruby 1.8中的一个方法,而是硬连接为调用==的否定
#2
3
Since the second half of the question hasn't been answered yet:
既然问题的后半部分还没有答案:
'A'.send(:==, 'B').send(:!) # Ruby 1.9
!'A'.send(:==, 'B') # Ruby 1.8
#1
5
!=
isn't a method in ruby 1.8 It's hardwired to be the negation of calling ==
!=不是ruby 1.8中的一个方法,而是硬连接为调用==的否定
#2
3
Since the second half of the question hasn't been answered yet:
既然问题的后半部分还没有答案:
'A'.send(:==, 'B').send(:!) # Ruby 1.9
!'A'.send(:==, 'B') # Ruby 1.8