str.each in Ruby isn't working

筅森魡賤 提交于 2019-11-30 11:02:23
scottd

Ruby 1.9 no longer has each on the String class. Use either each_char or each_line depending on what you want to do. The docs for Ruby 1.9 String are http://ruby-doc.org/core-1.9.3/String.html.

Use each_char instead:

"hello\nworld".each_char {|s| p s}

as to why it's not working, it works in 1.8 but not 1.9.

You're looking at the docs for 1.8. String#each has been removed in 1.9. Use each_line instead.

Ben

Works in 1.8.7, doesn't show up in the 1.9 docs -- must have been deprecated.

Here we go: https://web.archive.org/web/20090423003136/http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l113

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