我遇到了特殊字符(或西班牙語中的重音)正常化問題。我創建了一個GEM作爲學習練習(關於如何創建,安裝和使用個人創業板),但不幸的是,當我在另一個ruby文件中加載gem時,我遇到了標題錯誤。下面的代碼顯示了我的創業板是由什麼構成的(我知道代碼非常糟糕,但這又是一次學習練習)。個人創建的GEM的語法錯誤(意外' n',期待tCOLON2或'['或'。'(SyntaxError))
#!/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
然而,當我打開另一ruby文件我得到以下錯誤
/Users/Andre/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/這種寶石site_ruby/1.9.1/rubygems/custom_require.rb:60: `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或'['或'。' (SyntaxError)
我一直嘗試不同的東西,但我一直無法解決它。有人能幫助我確定我在做什麼錯誤嗎?
我的創業項目都可以在這裏找到:https://github.com/betogess506/Spanish-String-Normalizer
在我的環境中,它不返回錯誤。 – sawa
看起來錯誤是由配置引起的,在測試之前缺少'gem build'或'gem install'步驟,或者某些代碼在此處未顯示? @sawa:雖然我確信你試圖表現出一些「強硬的愛」,但我認爲這個評論對OP來說過於消極。國際海事組織需要一段時間才能進行專業編碼,然後才能獲得有用的評論 –
@NeilSlater好吧,我會重新說明它:除了錯誤(我無法複製),問題中的代碼有很多問題。 – sawa