Class: Ducktape::Expression::IndexerExp

Inherits:
Object
  • Object
show all
Includes:
BinaryOpExp, Ref
Defined in:
lib/ducktape/expression/indexer_exp.rb

Overview

Instance Attribute Summary

Attributes included from BinaryOpExp

#left, #owner, #right

Instance Method Summary collapse

Methods included from BinaryOpExp

#initialize

Instance Method Details

#bind(src, type, qual = nil, root = src) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ducktape/expression/indexer_exp.rb', line 9

def bind(src, type, qual = nil, root = src)
  unbind
  src = left.bind(src, :path, qual, root)
  @source = WeakReference.new(src)
  @type = type
  params.each { |param| param.bind(root, :path) }

  src.on_store(self) if src.is_a?(Hookable) && src.respond_to?(:on_store) #convention hook for []=

  value
end

#call(parms) ⇒ Object



33
34
35
36
37
38
# File 'lib/ducktape/expression/indexer_exp.rb', line 33

def call(parms)
  parms = parms.args.dup
  parms.pop
  return unless parms == params_values
  owner.send("#{@type}_changed")
end

#owner=(o) ⇒ Object



40
41
42
43
# File 'lib/ducktape/expression/indexer_exp.rb', line 40

def owner=(o)
  @owner, left.owner = o, o
  params.each { |param| param.owner = o }
end

#rightmostObject



45
46
47
# File 'lib/ducktape/expression/indexer_exp.rb', line 45

def rightmost
  self
end

#unbindObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ducktape/expression/indexer_exp.rb', line 21

def unbind
  params.each { |param| param.unbind }

  return unless @source
  src = @source.object
  return @source, @type, @qual = nil unless src

  src = source
  src.remove_hook(:on_store, self) if src.is_a?(Hookable) && src.respond_to?(:on_store)
  nil
end

#unparseObject



49
50
51
# File 'lib/ducktape/expression/indexer_exp.rb', line 49

def unparse
  "#{left.unparse}[#{params.map(&:unparse).join(',')}]"
end

#valueObject



53
54
55
# File 'lib/ducktape/expression/indexer_exp.rb', line 53

def value
  source[*params_values]
end

#value=(v) ⇒ Object



57
58
59
# File 'lib/ducktape/expression/indexer_exp.rb', line 57

def value=(v)
  source[*params_values] = v
end