ruby - Syntax error on personally created GEM ( unexpected '\n', expecting tCOLON2 or '[' or '.' (SyntaxError) ) -


i encountered problem normalizing special characters (or accents in spanish). created gem learning exercise (on how create, install , use personal gem), unfortunately run error on title, whenever load gem on ruby file. code below shows gem made of (i know code bad again it's learning exercise).

#!/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                                     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 

however when load gem on ruby file following error

/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: syntax error, unexpected '\n', expecting tcolon2 or '[' or '.' (syntaxerror)

i keep trying different things haven't been able solve it. can me identify mistake i'm doing?

my gem project can found here: https://github.com/betogess506/spanish-string-normalizer

i've tried code can't reproduce error on system (neither using ruby 2.0.0 or 1.9.3). think it's not worth bothering troublshooting problem, because code can written using string#tr method:

module spanishstringnormalizer       def self.normalize(string)     string.tr('áéíóú', 'aeiou')   end end  spanishstringnormalizer.normalize('fóó') # => "foo" 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -