Sha256: 55954624e09af9fc4947c978663b0683315034cc3ecbb253b09df660780666e0
Contents?: true
Size: 746 Bytes
Versions: 2
Compression:
Stored size: 746 Bytes
Contents
Schema = _ = StrongJSON.new do # @type self: AddressSchema let :address, object(address: string, country: symbol?) let :email, object(email: string) let :contact, enum?(address, email) let :person, object(name: string, contacts: array(contact)) end person = Schema.person.coerce(nil) # @type var name: String name = person[:name] # @type var contacts: Array[email | address] contacts = person[:contacts] contacts.each do |contact| case when contact.keys.include?(:email) # @type var contact: email puts "Email: #{contact[:email]}" when contact.keys.include?(:address) # @type var contact: address puts "Address: #{contact[:address]} (#{contact[:country] || "unspecified"})" end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
strong_json-2.1.2 | example/lib/example.rb |
strong_json-2.1.1 | example/lib/example.rb |