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?
Constants in Ruby are “contantish”. And in your case you’re passing the array reference to job types, so any changes that you do in job_types it goes to ItServiceJob::TYPES.
With that being said what you need to do is duplicate the ItServiceJob::TYPES. Change the job_type assignment with:
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