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



243
244
245
# File 'lib/dhall/ast.rb', line 243

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

Instance Method Details

#as_jsonObject



251
252
253
254
255
256
257
# File 'lib/dhall/ast.rb', line 251

def as_json
  if name == "_"
    index
  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



247
248
249
# File 'lib/dhall/ast.rb', line 247

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