solnic / virtus

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

Attributes not set to the default value when passed nil #291

Closed miloshadzic closed 9 years ago

miloshadzic commented 9 years ago

I'm not sure if this is intended or not but:

class A
  include Virtus.value_object
  attribute :val, Symbol, default: :something
end

# case 1
A.new.val
# => :something
# case 2
A.new(val: nil).val
# => nil

I would expect case 2 to return the default value as well.

solnic commented 9 years ago

Yes this is intended as you explicitly set the value to nil. Defaults are only set when no value was passed in.