ashbb / shoes_tutorial_html

Shoes Tutorial Note : HTML version

This URL has Read+Write access

shoes_tutorial_html / mdowns / 00535_Scope__local_variable_and_instance_variable.mdown
f1a424bc » ashbb 2009-01-02 added sample60 and chapter ... 1 Scope: local variable and instance variable
2 -------------------------------------------
3 We need to learn the scope, the difference between local variable and instance variable, over and over again.
4
5 # sample60.rb
6 Shoes.app :width => 300, :height => 300 do
7 i = 45
8 button 'new'do
9 i += 5
10 box = rand(2) == 0 ? rect(i, i, 20) : oval(i, i, 20)
11 box.style :fill => send(COLORS.keys.map{|sym|sym.to_s}[rand(COLORS.keys.size)])
12
13 @flag = false
14 box.click{@flag = true; @box = box}
15 box.release{@flag = false}
16 motion{|left, top| @box.move(left-10, top-10) if @flag}
17 end
18
19 end
20
21 **sample60.png**
22
23 ![sample60.png](http://github.com/ashbb/shoes_tutorial_html/raw/master/images/sample60.png)
24
25 This snapshot is created by the following setps.
26 - clicked 'new' button 30 times
27 - picked up and drew 6 ovals to the lower side
28 - picked up and drew 7 rects to the upper side
a3548807 » ashbb 2009-10-18 Confirmed 00533-01000 with ... 29
30
31 Policeman
32 ---------
33
34 The sample60.rb worked well with Shoes-0.r1263