English 中文(简体)
Ruby: 在更新为 Ruby 1.9 之后, “ no methodError” “ no methodError”
原标题:Ruby: "NoMethodError" after updating to ruby 1.9

我知道这个问题可能看起来非常具体, 但我试图更新一些脚本, 以便运行在 Ruby 1. 9 上, 并且多次遇到这个非常相似的错误。 我试图在此运行此代码 : < a href=" http://x.gfax.ch/ Archives/Scripts/boggle.rb" rel = "nofollow" > http://x.gfax.ch/ Argives/Scripts/bogle.rb , 但卡在 :

def Dict.to_n(ch)
    ch[0]- a [0]
end

在 Ruby1.8 中, 这将生成一个随机 NxN boggle 板, 然后找到并输出它能找到的所有单词。 但在 Ruby1. 9 中, 翻译给我这个信息 :

boggle.rb:182:in `to_n : undefined method `-  for "a":String (NoMethodError)

我的语法有什么问题吗? (如果你需要一个字典文件来播放脚本, 我使用此示例页底部的字典文件 : < a href="http://learnruby.com/bogle/index.shtml" rel=“ nofollow” >http://learnruby.com/bogle/index.shtml ) 感谢您提前为任何指导 。

最佳回答

你也许想尝试一下这样的东西:

  def Dict.to_n(ch)
    if ch.respond_to? :codepoints #1.9+
      ch.codepoints.first -  a .codepoints.first
    else
      ch[0]- a [0]
    end
  end
问题回答

在Ruby 1.9中,方法这里 )。你不妨考虑使用string#charps 代替。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签