# Symbol\[int\] not working as expected

**URL:** <https://www.ruby-forum.com/t/symbol-int-not-working-as-expected/171677>\
**Category:** Rails\
**Created:** [July 7, 2009, 3:08pm UTC](https://www.ruby-forum.com/t/symbol-int-not-working-as-expected/171677 "2009-07-07T15:08:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuart.coyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stuart.coyle](https://www.ruby-forum.com/u/stuart.coyle)\
**Post date:** [July 7, 2009, 3:08pm UTC](https://www.ruby-forum.com/t/symbol-int-not-working-as-expected/171677/1 "2009-07-07T15:08:18Z")

</div>

In Ruby 1.9 Symbol can receive [] and convert to a string and then  
index. I’ve confirmed this works as expected in the Rails console and  
irb.

I have a model with a method\_missing method defined. Like this:

def method\_missing(name, \*args, &block)  
if name[-1] == ‘=’  
# Do some stuff and perhaps return  
end

```
  super

```

end

This throws: undefined method ‘[]’ for :title:Symbol (NoMethodError)  
‘title’ is one of the model’s attributes that is getting sent to the  
model in a view.  
Does Rails monkey with Symbol somewhere and undefine []?  
I’m stumped.

---

<div class="post-metadata">

**Author:** ![stuart.coyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stuart.coyle](https://www.ruby-forum.com/u/stuart.coyle)\
**Post date:** [July 7, 2009, 3:38pm UTC](https://www.ruby-forum.com/t/symbol-int-not-working-as-expected/171677/2 "2009-07-07T15:38:07Z")

</div>

Problem solved…  
irb, script/console were running ruby 1.9.1  
All my tests and specs running on 1.8.6  
…that’s not good.

Found with a spec:  
it “should be running Ruby 1.9.1” do  
RUBY\_VERSION.should == “1.9.1”  
end

On 07/07/2009 11:07pm, “stuart.coyle” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In Ruby 1.9 Symbol can receive [] and convert to a string and then

> index. I’ve confirmed this works as expected in the Rails console and

> irb.

> I have a model with a method\_missing method defined. Like this:

> def method\_missing(name, \*args, &block)

> if name[-1] == ‘=’

> # Do some stuff and perhaps return

> end

> super

> end

> This throws: undefined method ‘[]’ for :title:Symbol (NoMethodError)

> ‘title’ is one of the model’s attributes that is getting sent to the

> model in a view.

> Does Rails monkey with Symbol somewhere and undefine []?
