Class: Wee::Examples::Counter
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Component
#add_decoration, #backtrack_state_chain, #decoration, #decoration=, #do_render_chain, #each_decoration, #process_callbacks, #process_callbacks_chain, #remove_decoration, #remove_decoration_if
Methods inherited from Presenter
#do_render, #get_property, #lookup_property, #process_callbacks, #properties, #properties=, #session, template, uses_property
Constructor Details
#initialize(initial_count = 0) ⇒ Counter
Returns a new instance of Counter.
4
5
6
7
|
# File 'lib/wee/examples/counter.rb', line 4
def initialize(initial_count=0)
super()
@count = initial_count
end
|
Instance Attribute Details
Returns the value of attribute count.
2
3
4
|
# File 'lib/wee/examples/counter.rb', line 2
def count
@count
end
|
Instance Method Details
#backtrack_state(snap) ⇒ Object
9
10
11
12
|
# File 'lib/wee/examples/counter.rb', line 9
def backtrack_state(snap)
super
snap.add(self)
end
|
14
15
16
|
# File 'lib/wee/examples/counter.rb', line 14
def dec
@count -= 1
end
|
18
19
20
|
# File 'lib/wee/examples/counter.rb', line 18
def inc
@count += 1
end
|
22
23
24
25
26
27
28
|
# File 'lib/wee/examples/counter.rb', line 22
def render
r.anchor.callback(:dec).with("--")
r.space
render_count
r.space
r.anchor.callback(:inc).with("++")
end
|
#render_count ⇒ Object
30
31
32
|
# File 'lib/wee/examples/counter.rb', line 30
def render_count
r.text @count.to_s
end
|