views:

32

answers:

1

Hey,

I have encountered a weird problem twice in the past 2 weeks and it's starting to piss me off.

I have this very simple code :

  Rails.logger.debug "Is current_step frozen  ? => #{@current_step.frozen?.inspect}"
  @current_step += 1

Has you can (or not) imagine, this is what is displayed on my console :

Is current_step frozen  ? => false
Completed   in 264ms

TypeError (can't modify frozen object):
  lib/chuguf/core.rb:44:in `upgrade'
  app/controllers/xml/cheat_controller.rb:6:in `index'

Can some one tells me what's happen here ?

I can give more details if required but i don't see how other lines could be relevant. All the code is executed in the current thread.

Thanks for your help !

+4  A: 

You're not trying to mutate @current_step (which isn't possible with integers anyway), you're trying to reassign it. Since reassigning an instance variable means mutating the object the instance variable belongs to (i.e. self), you can only do so if self is not frozen.

In other words: if you change your debug message to tell your whether self is frozen instead of @current_step, you'll find out that it is and that's why you get the error.

sepp2k
Ok you are right :D Now the question is, how to store an object into the cache without freezing it ? :p thanks !
Niklaos