Skip to content

Instantly share code, notes, and snippets.

@careo
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save careo/9283113 to your computer and use it in GitHub Desktop.
Save careo/9283113 to your computer and use it in GitHub Desktop.
freezing strings
RUBY_DESCRIPTION # => "ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]"
"one".freeze.object_id # => 70098950078640
one = "one"
two = "one"
one.object_id # => 70098950065800
two.object_id # => 70098950065780
one.freeze
two.freeze
one.object_id # => 70098950065800
two.object_id # => 70098950065780
"one".freeze.object_id # => 70098950078640
"one".freeze.object_id # => 70098950078640
hash = {}
hash["one"] = "something"
hash.keys.first.object_id # => 70098950062960
hash.delete "one"
hash["one"] = "something"
hash.keys.first.object_id # => 70098950062360
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment