Created
March 20, 2018 15:21
-
-
Save novikserg/476f138535a3fbb3d899b1dbaa119db7 to your computer and use it in GitHub Desktop.
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
class Foo | |
MY_CONST = "hello".freeze | |
end | |
puts Foo::MY_CONST # "hello" | |
Foo.const_set("MY_CONST", "new const") | |
puts Foo::MY_CONST # "new const" | |
class Foo | |
def self.my_const | |
"hello" | |
end | |
end | |
puts Foo.my_const # "hello" | |
Foo.my_const.concat("foobar") # that's what we are afraid of without `.freeze` in constants | |
puts Foo.my_const # still "hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment