My Profile Photo

Personal Webpage of David Duggins


Well, I was born on a normal day in July, 1981 and have been creating chaos ever since. Born in North Carolina, but raised in the aftermath of the Soviet Union, Kazakhstan, I have been messing around with computers nearly my entire life. I wrote my first program in assembly when I was 11. In my early teens I ran a BBS connected to Fidonet and started building a website for my band. In 1999 I was introduced to Linux, and it was love at first compile. I started my career in IT in the early 2000's doing IT for a Car Dealership in Charlotte NC. I wrote my first major web app in Cold Fusion (an ecom app) at that time. In 2006 I left Charlotte and moved down to Columbia where starting working as a developer, freelancer and consultant. Currently I am working as a freelance developer and DevOps consultant!!


Thoughts on Rails Freeze

So I saw a post about a Rails function freeze that caught my attention. I would like to speak on it a bit. So basically, for the uninitiated, The freeze method lets you set an object in rails to be immuttable.

For example:

name = "Robert"
new_name = name

name[0] = T

name       #Tobert
new_name   #Tobert

See, in this instance, we have created a link between the object, name and new_name. Change one and we change the other one.

This is where freeze comes in. If we freeze name: name.freeze then try to change name directly, we get an error. If we change new_name it will not change name.

So if right be the change I add the code:

name.freeze

I’ll get an error message can't modify frozen String: "Robert" (FrozenError)

© 2024 David Duggins. All rights reserved.