Skip to content

Instantly share code, notes, and snippets.

@novikserg
Created March 20, 2018 15:21
Show Gist options
  • Save novikserg/476f138535a3fbb3d899b1dbaa119db7 to your computer and use it in GitHub Desktop.
Save novikserg/476f138535a3fbb3d899b1dbaa119db7 to your computer and use it in GitHub Desktop.
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