On 25 March 2010 14:47, Adrien Coquio <[email protected]> wrote:
> In fact the previous example doesn't change the value of
> PeopleHelpers::MYCONSTANT
>
> but if I do :
> <%
>  joke = PeopleHelpers::MYCONSTANT.dup
>  joke[:opt][:title].sub!('a','b')
>  #if i debug there, PeopleHelpers::MYCONSTANT = {:opt => {:title =>
>  bbcdef}}
> %>
>
> the value changed.. why ?
>

My understanding is that dup makes a copy of the hash contents, but
since the contents are themselves references rather than simple
objects you end up with a new hash containing references to the same
objects, which can then be modified as you have noted (even though
they are notionally constant).

Colin

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to