Created
June 1, 2011 20:51
-
-
Save aberant/1003283 to your computer and use it in GitHub Desktop.
you can't freeze constants in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOB = 3 #=> 3 | |
BOB.freeze #=> 3 | |
BOB = 4 # (irb):4: warning: already initialized constant BOB #=> 4 | |
BOB #=> 4 |
(freezing works on instances of objects, and has nothing to do with assignments)
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
I see you missed the twitter conversation that went with this (x.x)
…On Jun 1, 2011 8:04 PM, "toothrot" < ***@***.***> wrote:
That's not what freezing does, anyway O.o
``` ruby
a = 1 # => 1
a.freeze # => 1
a = 2 # => 2
a # => 2
b = "" # => ""
b.freeze #=> ""
b << "foo" #TypeError: can't modify frozen string
```
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1003283
=(
I was talking about the pointlessness of freezing value objects! See, now
its like you where here all along!
…On Jun 1, 2011 8:34 PM, "toothrot" < ***@***.***> wrote:
=(
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1003283
so i see!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's not what freezing does, anyway O.o