Module: VisualizeRuby::Touchable

Included in:
Edge, Node
Defined in:
lib/visualize_ruby/touchable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#touchedObject (readonly)

Returns the value of attribute touched.



28
29
30
# File 'lib/visualize_ruby/touchable.rb', line 28

def touched
  @touched
end

Instance Method Details

#post_initialize(**args) ⇒ Object



3
4
5
6
7
8
# File 'lib/visualize_ruby/touchable.rb', line 3

def post_initialize(**args)
  self.class.add_names(:touched_display, :step_display)
  @steps   = []
  @touched = 0
  super if defined? super
end

#step_displayObject



22
23
24
25
26
# File 'lib/visualize_ruby/touchable.rb', line 22

def step_display
  unless @steps.empty?
    "step: #{@steps.join(", ")}"
  end
end

#touch(color, step: nil) ⇒ Object



10
11
12
13
14
# File 'lib/visualize_ruby/touchable.rb', line 10

def touch(color, step: nil)
  @steps << step
  options.merge!(color: color)
  @touched += 1
end

#touched_displayObject



16
17
18
19
20
# File 'lib/visualize_ruby/touchable.rb', line 16

def touched_display
  unless [0, 1].include?(@touched)
    "(called: #{@touched})"
  end
end