Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBinary Soul
4,592 PointsRuby Problem with Unicode
Hello,
i wrote this:
class DerGanzeSatz
attr_reader :arg1
def initialize(arg1)
unify(arg1)
end
def unify(arg1)
arg1 = arg1.unicode_normalize!
splitting(arg1)
end
def splitting(arg1)
split_all = arg1.split(/\W+/)
washing(split_all)
end
def washing(arg1)
washing = arg1
washing.uniq!
end
end
truewords = []
print "> "
write = DerGanzeSatz.new(gets.chomp)
and it always gives out that error:
ruby test.rb
> In diesem Satz kommen Wörter doppelt vor! Den Wörter kommen in Sätzen oft doppelt vor!
Traceback (most recent call last):
6: from /test.rb:26:in `<main>'
5: from /test.rb:26:in `new'
4: from /test.rb:5:in `initialize'
3: from /test.rb:9:in `unify'
2: from /test.rb:9:in `unicode_normalize!'
1: from /lib/ruby/2.5.0/unicode_normalize/normalize.rb:126:in `normalize'
lib/ruby/2.5.0/unicode_normalize/normalize.rb:126:in `gsub': invalid byte sequence in UTF-8 (ArgumentError)
Does someone have a hint how to deal with that problem WITHOUT stripping letters?
1 Answer
Jeremy Hill
29,567 PointsI believe your problem is in this code:
def washing(arg1)
washing = arg1
washing.uniq!
end
# you are calling the method inside of the method without an argument
# I would change the local variable 'washing' to washing_1 or something so you don't get the error.
# make sure that you change the return variable name as well.
Binary Soul
4,592 PointsBinary Soul
4,592 PointsHi thanks for your participation. The code works, as long as you type just english words. If you beginn to type german (which is nescessary for the programm to have use, once it done) you get this message. My System is UTF-8, my editor saves in UTF-8 and well.. just ruby seems not to understand non-english letters.
Even if I try to use .encode(UTF-8) or .force_encoding(UTF-8)... everything runs into this error message.