我在规范化特殊字符(或西班牙语的重音符号)时遇到了问题。我创建了一个 GEM 作为学习练习(关于如何创建、安装和使用个人 gem),但不幸的是,每当我将 gem 加载到另一个 ruby 文件时,我都会遇到标题错误。下面的代码显示了我的 GEM 是由什么组成的(我知道代码非常糟糕,但它又是一个学习练习)。
#!/bin/env ruby
# encoding: utf-8
module SpanishStringNormalizer
class Normalizer
def self.spanishNormalize (aString)
while (aString.include? "á") ==true ||
(aString.include? "é") ==true ||
(aString.include? "í") ==true ||
(aString.include? "ó") ==true ||
(aString.include? "ú") ==true do
aString ["á"]= "a" if aString.include? "á"
aString ["é"]= "e" if aString.include? "é"
aString ["í"]= "i" if aString.include? "í"
aString ["ó"]= "o" if aString.include? "ó"
aString ["ú"]= "u" if aString.include? "ú"
end #end of while
return aString
end #end of spanishNormalize
end #end of class
end #end of module
但是,当我将此 gem 加载到另一个 ruby 文件时,我收到以下错误
/Users/Andre/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require': /Users/Andre/.rvm/gems /ruby-1.9.3-p429/gems/Spanish String Normalizer-0.0.0/lib/spanish_str_normalizer.rb:25:语法错误,意外 '\n',需要 tCOLON2 或 '[' 或 '.' (语法错误)
我一直在尝试不同的事情,但我无法解决它。有人可以帮我确定我在哪里做错了吗?
我的 GEM 项目可以在这里找到:https ://github.com/betogess506/Spanish-String-Normalizer