solnic / virtus

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

Hash coercion fails for ValueObject #173

Closed changeclay closed 11 years ago

changeclay commented 11 years ago

E.g. using

Hash[String => Integer]

When I initialize, I get:

 ArgumentError:
  more than one [key => value] pair in `{String=>Integer, :writer=>:private}`
cored commented 11 years ago

@changeclay I tried to replicate your error with this

https://gist.github.com/cored/5768920

But couldn't am I missing something?

changeclay commented 11 years ago
require 'virtus'

class Apple
  include Virtus::ValueObject
  attribute :metrics, Hash[String => Integer]
end
ruby virtus_test.rb
ArgumentError: more than one [key => value] pair in `{String=>Integer, :writer=>:private}`
cored commented 11 years ago

Thanks I will try to figure this out :-)

dkubb commented 11 years ago

I'm guessing there's somewhere in the code that processes the arguments passed into #attribute that assumes the last argument is a Hash of options, when it really is the type, and then it mixes in some defaults into what it thinks are "options". Some validation code then blows up when it checks the type.