solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 228 forks source link

Attributes of type Range raise an exception when trying to instantiate an object #253

Closed marten closed 9 years ago

marten commented 10 years ago
require 'virtus'

class A
  include Virtus.model
  attribute :foo, Range
end

A.new
# => ArgumentError: wrong number of arguments (0 for 2..3)
# => from /Users/marten/.gem/ruby/2.1.0/gems/virtus-1.0.1/lib/virtus/attribute/collection.rb:9:in `initialize'

Offending line is: default Proc.new { |_, attribute| attribute.primitive.new }. Range ofcourse does not have a argumentless constructor, a range always needs a beginning and an end.

I'd like to just have nil when nothing is given. Setting attribute :foo, Range, default: nil doesn't help.

Hampei commented 10 years ago

Will be fixed with https://github.com/solnic/virtus/pull/261

solnic commented 9 years ago

This was fixed and I'm about to push 1.0.3 :fireworks: