Class: Dhall::Merge

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

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

Class Method Details

.decode(record, input, type = nil) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/dhall/binary.rb', line 126

def self.decode(record, input, type=nil)
	new(
		record: Dhall.decode(record),
		input:  Dhall.decode(input),
		type:   type.nil? ? nil : Dhall.decode(type)
	)
end

Instance Method Details

#as_jsonObject



651
652
653
654
# File 'lib/dhall/ast.rb', line 651

def as_json
	[6, record.as_json, input.as_json] +
		(type.nil? ? [] : [type.as_json])
end

#normalizeObject



299
300
301
302
303
304
305
306
307
308
# File 'lib/dhall/normalize.rb', line 299

def normalize
	normalized = super
	if normalized.record.is_a?(Record) && normalized.input.is_a?(Union)
		fetched = normalized.record.fetch(normalized.input.tag)
		value = normalized.input.value
		value.nil? ? fetched : fetched.call(value)
	else
		normalized
	end
end