Skip to content

Instantly share code, notes, and snippets.

@smcabrera
Created October 26, 2018 18:17
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 smcabrera/66e9cb31b136c7fecc904484602d15c0 to your computer and use it in GitHub Desktop.
Save smcabrera/66e9cb31b136c7fecc904484602d15c0 to your computer and use it in GitHub Desktop.
FIRST_ARRAY = [
FIRST_CONSTANT = "first constant value",
SECOND_CONSTANT = "second constant value"
].freeze
SECOND_ARRAY = [
FIRST_CONSTANT = "first constant value REDEFINED!!!!",
SECOND_CONSTANT = "DANGER"
].freeze
puts FIRST_ARRAY[0] # => first constant value
puts SECOND_ARRAY[0] # => first
puts FIRST_ARRAY[1] # => second constant value
puts SECOND_ARRAY[1]
# So far so good
# But then remember these arrays don't contain constants...they just contain strings
puts FIRST_ARRAY.inspect # => ["first constant value", "second constant value"]
# If we were to directly access those constants we've defined we'll actually get different values than what's in the arrays. Not good :/
puts FIRST_CONSTANT # => first constant value REDEFINED!!!!
# As we can see freezing the arrays doesn't help since the arrays we're freezing are of strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment