Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

ruby - Why word 'translate' is messing irb?

I don't understand why my method translate undefines start_with? method and is messing something in irb, so I can exit irb only by pressing Ctrl+d, not exit or quit:

>> "hello".respond_to?(:start_with?)
=> true
>> def translate(string)                                                                                                                   
>>   if string.start_with?("a", "e", "i", "o", "u")
>>     string += "ay"                                                                                                                      
>> end
>> end
NoMethodError: undefined method `start_with?' for #<RubyVM::InstructionSequence:0x00000001d4c960>
        from (irb):3:in `translate'
        from /usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
>> "hello".respond_to?(:start_with?)                                                                                                       
NoMethodError: undefined method `start_with?' for <RubyVM::InstructionSequence:irb_binding@(irb)>:RubyVM::InstructionSequence
        from (irb):3:in `translate'
        from /usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
>> exit
NoMethodError: undefined method `start_with?' for <RubyVM::InstructionSequence:irb_binding@(irb)>:RubyVM::InstructionSequence
        from (irb):3:in `translate'
        from /usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
>> quit
NoMethodError: undefined method `start_with?' for <RubyVM::InstructionSequence:irb_binding@(irb)>:RubyVM::InstructionSequence
        from (irb):3:in `translate'
        from /usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
>>  

I tried two different workspaces and effect is the same.
My Ruby and Rails versions are:

~/workspace $ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
~/workspace $ rails -v
Rails 4.2.2

from my other question I know that word translate is used by many I18N libraries, so it's my only suspect, hence the title of this question. However as a beginner, I don't see any relation.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is a bug in YARV that was fixed in YARV 2.4.0.

The commit message mentions the following workaround if you don't have YARV 2.4.0:

class << RubyVM::InstructionSequence
  def translate; end
  undef translate
end

Note that other implementations are not affected, only YARV.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...