Max Williams
2008-Sep-16 13:29 UTC
Clash between rails and facets for String exension ''chars''
We''ve got a problem with the facets gem - i started using facets because it has some very handy stuff. However, there seems to be a clash with rails over the extended method String#chars. in rails, String#chars returns a utf8-safe Chars object:>> "hello world!".chars=> #<ActiveSupport::Multibyte::Chars:0xb657b410 @string="hello world!"> in facets, String#chars returns an array of one-character strings, or at least that''s what the api says: http://facets.rubyforge.org/doc/index.html However, when i require ''facets'' in my environment.rb, and load the console, i get the same result as the rails version, ie a Chars object. Or, at least it looks the same, but it isn''t. The difference is revealed when i try to add a string to the Chars object: #without facets required>> "hello world!".chars[0..4] + "..."=> #<ActiveSupport::Multibyte::Chars:0xb6652c80 @string="hello ..."> #with facets required>> "hello world!".chars[0..4] + "..."ArgumentError: wrong number of arguments (2 for 1) from /home/max/work/e_learning_resource/branches/bundles/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/multibyte/chars.rb:87:in `+'' from /home/max/work/e_learning_resource/branches/bundles/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/multibyte/chars.rb:87:in `send'' from /home/max/work/e_learning_resource/branches/bundles/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/multibyte/chars.rb:87:in `method_missing'' from (irb):3 So, i have two questions... a) Is there a way to keep facets but to make rails override any methods with the same name, so i automatically use the rails version of chars but can still use the other handy facets extensions? b) How come, with facets required, String#chars is returning a Chars object when the facets api says it returns an array of 1-character strings? any advice/help welcome! thanks, max -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---