Symbol[int] not working as expected

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.

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” [email protected] 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 []?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs