[ create a new paste ] login | about

Link: http://codepad.org/FpOJwNYq    [ raw code | output | fork ]

Ruby, pasted on Mar 29:
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


Output:
1
2
Line 8:in `new': {:a=>1} is not a symbol (TypeError)
	from t.rb:8


Create a new paste based on this one


Comments: