Why word 'translate' is messing irb?

末鹿安然 提交于 2019-11-29 16:01:46

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.

Here is a theory

  • There is probably a global function translate in your setup
  • This function is called with an instruction sequence as argument when irb prints the output
  • Hence when you redefine translate printing the output breaks

The NoMethodError: undefined method does not mean that the method has been undefined globally but that it is being sent to an object that does not understand it

You can test my theory by executing

method(:translate)

If you get a result back then translate is already defined and your must not redefine it!

Now if you want to know which gem defined this function, install pry gem (which is a better irb) and use the $ command to look at the file and source code of that method

# Use this command in pry to see location and source code
$ translate
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!