Array#rotate产生NoMethoderror

时间:2013-02-01 16:04:23

标签: ruby

  

可能重复:
  Array#rotate equivalent in ruby 1.8.7

根据ruby-doc.org,我输入的语法应该正常工作,但在IRB中运行时会产生NoMethod错误。

>> a = ["1", "2", "3", "4", "5"]
=> ["1", "2", "3", "4", "5"]
>> a.rotate
NoMethodError: undefined method `rotate' for ["1", "2", "3", "4", "5"]:Array
    from (irb):14

发生此错误的原因是什么?

1 个答案:

答案 0 :(得分:4)

这是Ruby 1.9的新功能。您必须使用Ruby 1.8.6或1.8.7。

Here is what you can do