开发者

"test".partition("s") calls partition from Enumerable module instead of String module

开发者 https://www.devze.com 2023-03-16 16:25 出处:网络
I have tried to partition a string using the partition method from the String module. However, when doing so:

I have tried to partition a string using the partition method from the String module. However, when doing so:

puts "test".partition("s")

I get the following error message:

Line 1:in `partition': wrong number of arguments (1 for 0) (ArgumentError) from t.rb:1

I believe that Ruby calls the par开发者_开发百科tition method from the Enumerable module, instead of the one from the String module as I wanted.

How can I get Ruby to call the desired method?


As injekt has pointed out, 1.8.4 is too old. APIdock shows that String#partition only appears in 1.8.7. Upgrade.

0

精彩评论

暂无评论...
验证码 换一张
取 消