# Clash between rails and facets for String exension 'chars'

**URL:** <https://www.ruby-forum.com/t/clash-between-rails-and-facets-for-string-exension-chars/148714>\
**Category:** Rails\
**Created:** [September 16, 2008, 3:29pm UTC](https://www.ruby-forum.com/t/clash-between-rails-and-facets-for-string-exension-chars/148714 "2008-09-16T15:29:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 16, 2008, 3:29pm UTC](https://www.ruby-forum.com/t/clash-between-rails-and-facets-for-string-exension-chars/148714/1 "2008-09-16T15:29:00Z")

</div>

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](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
