Skip to content

Instantly share code, notes, and snippets.

@stp-che
Last active February 29, 2016 11:28
Show Gist options
  • Save stp-che/471afff91422141a9982 to your computer and use it in GitHub Desktop.
Save stp-che/471afff91422141a9982 to your computer and use it in GitHub Desktop.
require 'active_support/all'
class A < HashWithIndifferentAccess
end
class B < HashWithIndifferentAccess
def initialize(*args)
super
freeze
end
end
a = A.new.tap &:freeze
p a.merge(x: 1) # => {"x"=>1}
b = B.new
p b.merge(x: 1) # .../active_support/hash_with_indifferent_access.rb:125:in `default=': can't modify frozen B (RuntimeError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment