问题描述
我不明白为什么我的方法 translate
未定义 start_with?
方法并且在 irb 中搞乱了一些东西,所以我只能按 +,不是 exit
或 quit
:
>>你好".respond_to?(:start_with?)=>真的>>定义翻译(字符串)>>if string.start_with?("a", "e", "i", "o", "u")>>字符串 += "ay">>结尾>>结尾NoMethodError:未定义的方法start_with?"对于#<RubyVM::InstructionSequence:0x00000001d4c960>来自 (irb):3:在‘翻译’中来自/usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `'>>你好".respond_to?(:start_with?)NoMethodError:未定义的方法start_with?"对于 <RubyVM::InstructionSequence:irb_binding@(irb)>:RubyVM::InstructionSequence来自 (irb):3:在‘翻译’中来自/usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `'>>出口NoMethodError:未定义的方法start_with?"对于 <RubyVM::InstructionSequence:irb_binding@(irb)>:RubyVM::InstructionSequence来自 (irb):3:在‘翻译’中来自/usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `'>>放弃NoMethodError:未定义的方法start_with?"对于 <RubyVM::InstructionSequence:irb_binding@(irb)>:RubyVM::InstructionSequence来自 (irb):3:在‘翻译’中来自/usr/local/rvm/rubies/ruby-2.3.0/bin/irb:11:in `'>>
我尝试了两个不同的工作区,效果是一样的.
我的 Ruby 和 Rails 版本是:
~/workspace $ ruby -v红宝石 2.3.0p0(2015-12-25 修订版 53290)[x86_64-linux]~/工作区 $ rails -v导轨 4.2.2
来自我的另一个问题我知道这个词 translate
被许多 I18N 库使用,所以它是我唯一的怀疑,因此这个问题的标题.但是作为初学者,我看不出任何关系.
这是 YARV 中的一个错误 已在 YARV 2.4.0 中修复.
如果您没有 YARV 2.4.0,提交消息中提到了以下解决方法:
class <<RubyVM::指令序列定义翻译;结尾undef 翻译结尾
请注意,其他实现不受影响,只有 YARV.
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 +, 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.
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:
Note that other implementations are not affected, only YARV.
这篇关于为什么“翻译"这个词会弄乱irb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!