Class: Dhall::Variable

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#&, #*, #+, #<<, #as_dhall, #cache_key, #call, #concat, decode, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #normalize, #resolve, #slice, #to_cbor, #to_proc, #|

Class Method Details

.[](name, index = 0) ⇒ Object



245
246
247
# File 'lib/dhall/ast.rb', line 245

def self.[](name, index=0)
	new(name: name, index: index)
end

Instance Method Details

#as_jsonObject



253
254
255
256
257
258
259
260
261
# File 'lib/dhall/ast.rb', line 253

def as_json
	if name == "_"
		index
	elsif index.zero?
		name
	else
		[name, index]
	end
end

#shift(amount, name, min_index) ⇒ Object



129
130
131
132
133
# File 'lib/dhall/normalize.rb', line 129

def shift(amount, name, min_index)
	return self if self.name != name || min_index > index

	with(index: index + amount)
end

#substitute(var, with_expr) ⇒ Object



135
136
137
# File 'lib/dhall/normalize.rb', line 135

def substitute(var, with_expr)
	self == var ? with_expr : self
end

#to_sObject



249
250
251
# File 'lib/dhall/ast.rb', line 249

def to_s
	"#{name}@#{index}"
end