Class: Dhall::RecordType

Inherits:
Expression show all
Defined in:
lib/dhall/ast.rb,
lib/dhall/binary.rb

Direct Known Subclasses

EmptyRecordType

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#&, #*, #+, #annotate, #as_dhall, #cache_key, #call, #concat, #deep_merge, #dhall_eq, #digest, #fetch, #fusion, #merge, #normalize, #resolve, #shift, #substitute, #to_binary, #to_cbor, #to_proc, #to_s, #|

Class Method Details

.decode(record) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/dhall/binary.rb', line 136

def self.decode(record)
	if record.empty?
		EmptyRecordType.new
	else
		new(record: Hash[record.map { |k, v| [k, Dhall.decode(v)] }])
	end
end

.for(types) ⇒ Object



674
675
676
677
678
679
680
# File 'lib/dhall/ast.rb', line 674

def self.for(types)
	if types.empty?
		EmptyRecordType.new
	else
		RecordType.new(record: types)
	end
end

Instance Method Details

#==(other) ⇒ Object



704
705
706
# File 'lib/dhall/ast.rb', line 704

def ==(other)
	other.respond_to?(:record) && record.to_a == other.record.to_a
end

#as_jsonObject



712
713
714
# File 'lib/dhall/ast.rb', line 712

def as_json
	[7, Hash[record.to_a.map { |k, v| [k, v.as_json] }.sort]]
end

#deep_merge_type(other) ⇒ Object



688
689
690
691
692
693
694
# File 'lib/dhall/ast.rb', line 688

def deep_merge_type(other)
	return super unless other.class == RecordType

	with(record: Hash[record.merge(other.record) { |_, v1, v2|
		v1.deep_merge_type(v2)
	}.sort])
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


708
709
710
# File 'lib/dhall/ast.rb', line 708

def eql?(other)
	self == other
end

#keysObject



696
697
698
# File 'lib/dhall/ast.rb', line 696

def keys
	record.keys
end

#merge_type(other) ⇒ Object



682
683
684
685
686
# File 'lib/dhall/ast.rb', line 682

def merge_type(other)
	return self if other.is_a?(EmptyRecordType)

	with(record: record.merge(other.record))
end

#slice(keys) ⇒ Object



700
701
702
# File 'lib/dhall/ast.rb', line 700

def slice(keys)
	RecordType.for(record.select { |k, _| keys.include?(k) })
end