Single (non-Array-wrapped) values can be assigned to elements, but not at initialization. Consider this code sample:
# Initializing an Array-wrapped value
range = FHIR::Range.new(low: [FHIR::Quantity.new(value: 18)])
range.valid? # => true
# Setting a value
range.low = FHIR::Quantity.new(value: 18)
range.valid? # => true
puts range.to_json # => ... (valid FHIR JSON)
# Initializing plain value
range = FHIR::Range.new(low: FHIR::Quantity.new(value: 18))
# => Error: NoMethodError: undefined method `[]' for #<FHIR::Quantity:0x0055e8f174e6d8 @id=nil, @extension=[], @value=18, @comparator=nil, @unit=nil, @system=nil, @code=nil>
# => from /home/vagrant/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/fhir_models-3.0.2/lib/fhir_models/bootstrap/model.rb:58:in `method_missing'
I'd love to be able to use nil or present (or similar), rather than have to check to see if the object is nil, [], or [Object].
Second possibility
All non-initialized elements with qty 0..1 could be initialized to [] instead of nil. That way, at least we can access something with [0] and see if it's nil, rather than doing .try(:[], 0), which is a little goofy.
Single (non-Array-wrapped) values can be assigned to elements, but not at initialization. Consider this code sample:
I'd love to be able to use
nilorpresent(or similar), rather than have to check to see if the object isnil,[], or[Object].Second possibility
All non-initialized elements with qty
0..1could be initialized to[]instead ofnil. That way, at least we can access something with[0]and see if it'snil, rather than doing.try(:[], 0), which is a little goofy.