In irb all works fine: # irb irb(main):001:0> require ''rubygems'' => true irb(main):002:0> require ''raspell'' => true irb(main):003:0> speller = Aspell.new("ru_RU") => #<Aspell:0x7f8692c9d158> irb(main):004:0> speller.suggestion_mode = Aspell::NORMAL => "normal" irb(main):005:0> speller.check("лошадь") => true But same in Rails project: require ''rubygems'' require ''raspell'' def xxx speller = Aspell.new("ru_RU") speller.suggestion_mode = Aspell::NORMAL @xxx = speller.check("лошадь").to_s end @xxx is false! Why? -- Posted via http://www.ruby-forum.com/.
Fresh Mix wrote:> In irb all works fine: > > # irb > irb(main):001:0> require ''rubygems'' > => true > irb(main):002:0> require ''raspell'' > => true > irb(main):003:0> speller = Aspell.new("ru_RU") > => #<Aspell:0x7f8692c9d158> > irb(main):004:0> speller.suggestion_mode = Aspell::NORMAL > => "normal" > irb(main):005:0> speller.check("лошадь") > => true > > But same in Rails project: > > require ''rubygems'' > require ''raspell'' > > def xxx > speller = Aspell.new("ru_RU") > speller.suggestion_mode = Aspell::NORMAL > @xxx = speller.check("лошадь").to_s > end > > @xxx is false! Why?Maybe: @xxx = false def xxx @xxx = true end puts @xxx --output:-- false -- Posted via http://www.ruby-forum.com/.
On Sun, May 3, 2009 at 6:09 AM, Fresh Mix <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > In irb all works fine: > > # irb > irb(main):001:0> require ''rubygems'' > => true > irb(main):002:0> require ''raspell'' > => true > irb(main):003:0> speller = Aspell.new("ru_RU") > => #<Aspell:0x7f8692c9d158> > irb(main):004:0> speller.suggestion_mode = Aspell::NORMAL > => "normal" > irb(main):005:0> speller.check("лошадь") > => true > > But same in Rails project: > > require ''rubygems'' > require ''raspell'' > > def xxx > speller = Aspell.new("ru_RU") > speller.suggestion_mode = Aspell::NORMAL > @xxx = speller.check("лошадь").to_s > end > > @xxx is false! Why?In Ruby, when one tries to access an instance variable directly, which is always private by default, the return value is nil until it has been properly initialized. You can access instance variables using an accessor on a class. In any case, I recommend that you get a copy of "Programming Ruby" or "Programming Ruby 1.9" and read the section on "Scope of Constant and Variables". Good luck, -Conrad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On May 3, 2:09 pm, Fresh Mix <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > require ''rubygems'' > require ''raspell'' > > def xxx > speller = Aspell.new("ru_RU") > speller.suggestion_mode = Aspell::NORMAL > @xxx = speller.check("лошадь").to_s > end >If your script contains only those lines then this is normal - you''ve defined an xxx method but you haven''t called it. Fred> @xxx is false! Why? > -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote:> On May 3, 2:09 pm, Fresh Mix <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> require ''rubygems'' >> require ''raspell'' >> >> def xxx >> speller = Aspell.new("ru_RU") >> speller.suggestion_mode = Aspell::NORMAL >> @xxx = speller.check("лошадь").to_s >> end >> > > If your script contains only those lines then this is normal - you''ve > defined an xxx method but you haven''t called it. > > FredI have <%= @xxx %> on view, and it prints false. Also I have tested many words from model, and all was false. for row in @results if speller.check(row["word"]) ... I have this problen only with russian words, english works fine. -- Posted via http://www.ruby-forum.com/.
On May 3, 6:19 pm, Fresh Mix <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have <%= @xxx %> on view, and it prints false. > > Also I have tested many words from model, and all was false. > > for row in @results > if speller.check(row["word"]) > ... > > I have this problen only with russian words, english works fine.You should have said that from the start :-). This points to an encoding problem, eg the default encoding used to read your source file being different from whatever was being used by irb (which may depend on terminal settings etc). Fred> -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote:> You should have said that from the start :-). This points to an > encoding problem, eg the default encoding used to read your sourceDatabase is in UTF-8, but it aslo doesn''t work if word is in controller sourse: speller.check("лошадь") So how can I test different encodings? -- Posted via http://www.ruby-forum.com/.
Fresh Mix wrote:> Frederick Cheung wrote: >> You should have said that from the start :-). This points to an >> encoding problem, eg the default encoding used to read your source > > Database is in UTF-8, but it aslo doesn''t work if word is in controller > sourse: speller.check("лошадь") > > So how can I test different encodings?What version of ruby are you using with rails? Are you using a different version of ruby for your irb tests? -- Posted via http://www.ruby-forum.com/.
7stud -- wrote:> Fresh Mix wrote: >> Frederick Cheung wrote: >>> You should have said that from the start :-). This points to an >>> encoding problem, eg the default encoding used to read your source >> >> Database is in UTF-8, but it aslo doesn''t work if word is in controller >> sourse: speller.check("лошадь") >> >> So how can I test different encodings? > > What version of ruby are you using with rails? Are you using a > different version of ruby for your irb tests?I think, it is same, because I have only ruby 1.8.7 installed. $ ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] -- Posted via http://www.ruby-forum.com/.
resh Mix wrote:> > I think, it is same, because I have only ruby 1.8.7 installed. > > $ ruby -v > ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]Ok. ruby 1.8.* doesn''t understand multi-byte/unicode characters, like russian characters. ruby thinks that every character is an ascii character, where one byte equals one character. However, you aren''t asking a ruby method to do anything with your string--you are calling an aspell method. Is there any reason to believe that aspell can recognize a character that is made up of several bytes? As for irb, personally I never use the command line interactive mode in any language because after a few times spending hours trying to figure out why the results in interactive mode were different than in a program, I determined that I would never waste time doing that again. The only output that matters is your program''s output. Forget about what irb says and instead write a small example program when testing things out. If you write a small program, with the same content as irb, do you get true or false for your aspell calculations? -- Posted via http://www.ruby-forum.com/.
....... Anyway, by default Rails will set the encoding to UTF8 (just put Rails.logger.debug "Kcode: #{$KCODE}" to confirm this is the case for you). To see what encoding *is* working properly, just check the $KCODE global from irb. Then set that accordingly in your environment.rb and restart your app. On May 3, 4:46 pm, 7stud -- <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> resh Mix wrote: > > > I think, it is same, because I have only ruby 1.8.7 installed. > > > $ ruby -v > > ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] > > Ok. ruby 1.8.* doesn''t understand multi-byte/unicode characters, like > russian characters. ruby thinks that every character is an ascii > character, where one byte equals one character. However, you aren''t > asking a ruby method to do anything with your string--you are calling an > aspell method. Is there any reason to believe that aspell can recognize > a character that is made up of several bytes? > > As for irb, personally I never use the command line interactive mode in > any language because after a few times spending hours trying to figure > out why the results in interactive mode were different than in a > program, I determined that I would never waste time doing that again. > The only output that matters is your program''s output. Forget about > what irb says and instead write a small example program when testing > things out. > > If you write a small program, with the same content as irb, do you get > true or false for your aspell calculations? > > -- > Posted viahttp://www.ruby-forum.com/.
pharrington wrote:> ....... > > Anyway, by default Rails will set the encoding to UTF8 (just put > Rails.logger.debug "Kcode: #{$KCODE}" to confirm this is the case for > you). To see what encoding *is* working properly, just check the > $KCODE global from irb. Then set that accordingly in your > environment.rb and restart your app.Setting $KCODE to "u" in a ruby program is not a cure all. Not all the ruby methods will suddenly recognize that characters consist of multi-bytes. For instance, $KCODE = "n" str = "лошадь" puts str.length $KCODE = "u" puts str.length --output:-- 12 12 If $KCODE were a cure all, they(Matz, et al) would just switch it on in permanently, and the unicode problems would disappear. -- Posted via http://www.ruby-forum.com/.
can any solve this problem? -- Posted via http://www.ruby-forum.com/.