A stupidly simple implementation of a kind of "sorta immutable" struct that can be instantiated as conveniently as an OpenStruct
but after instantiation it doesn't let me (easily) add fields or mutate them:
guy = ClosedStruct.new( name: "John", age: 23 )
# readers:
guy.name #=> "John"
guy.age #=> 23
guy.xxx #=> NoMethodError: undefined method `xxx'...
# respond_to? and methods work as expected:
guy.respond_to? :age #=> true
guy.methods(false) #=> [:name, :age]
# in-place modification is prevented, but you can create modified copies with #merge:
guy.name = "Jack" #=> NoMethodError: undefined method `name='...
guy.merge name: "Jack" #=> a new ClosedStruct instance with name: "Jack", age: 23