Ruby on Rails
Monday, February 3, 2014
On Monday, February 3, 2014 9:36:25 AM UTC, Роман Ярыгин wrote:
Now, when I refresh the page every time, the array pops one by one item and finally get empty! But, why? Why the constant changes, not variable? What I'm doing wrong?
What is constant is that ItServiceJob::TYPES always gives you the same object (in terms of it object_id), but there is nothing to stop you modifying the object.
Furthermore, job_types = ITServiceJob::TYPES isn't copying ItServiceJob::TYPES, it is just creating a local variable that references the exact same ruby object. You can copy the array with .dup (this is a shallow copy). If you want to prevent modifications to an object you need to freeze it (by calling .freeze on it). After this any attempts to modify the object will raise an exception
Fred
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a88c6898-929c-4cf2-b281-3b98217e5bd6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment