Sha256: 27fa8bfb3f64cc8e3781030787a32cf56380aa9931cf2656c73b658c4a5bc226
Contents?: true
Size: 745 Bytes
Versions: 1
Compression:
Stored size: 745 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
strong_json-0.8.0 | example/example.rb |