Skip to content

Instantly share code, notes, and snippets.

@aberant
Created June 1, 2011 20:51
Show Gist options
  • Save aberant/1003283 to your computer and use it in GitHub Desktop.
Save aberant/1003283 to your computer and use it in GitHub Desktop.
you can't freeze constants in ruby
BOB = 3 #=> 3
BOB.freeze #=> 3
BOB = 4 # (irb):4: warning: already initialized constant BOB #=> 4
BOB #=> 4
@toothrot
Copy link

toothrot commented Jun 2, 2011

That's not what freezing does, anyway O.o

a = 1 # => 1
a.freeze # => 1
a = 2 # => 2
a # => 2

b = "" # => ""
b.freeze #=> ""
b << "foo" #TypeError: can't modify frozen string

@toothrot
Copy link

toothrot commented Jun 2, 2011

(freezing works on instances of objects, and has nothing to do with assignments)

@toothrot
Copy link

toothrot commented Jun 2, 2011

or constants, for that matter

FOO = "boo" # => "boo"
FOO << "barf" #=> "boobarf"
FOO.freeze # => "boobarf"
FOO << "cats" #TypeError: can't modify frozen string
FOO = "bar" #(irb):13: warning: already initialized constant FOO

@aberant
Copy link
Author

aberant commented Jun 2, 2011 via email

@toothrot
Copy link

toothrot commented Jun 2, 2011

=(

@aberant
Copy link
Author

aberant commented Jun 2, 2011 via email

@toothrot
Copy link

toothrot commented Jun 2, 2011

so i see!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment