1 2 3 4 5 6 7 8 9
class StructWithDefaults < Struct def initialize(*args) defaults = Hash === args.last ? args.pop : {} super(*(args + defaults.keys)) end end Foo = StructWithDefaults.new :a => 1 foo = Foo.new
1 2
Line 8:in `new': {:a=>1} is not a symbol (TypeError) from t.rb:8