![Page 2: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/2.jpg)
brian who?
2
So, who is this guy?Visit http://www.napcs.com/http://www.snippetstash.com/http://www.feelmyskills.com/http://www.webdesignfordevelopers.com
![Page 3: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/3.jpg)
Shoes?
3
A talk about shoes would be completely inappropriate at a code camp. So we’re not talking about these kinds of shoes. Although, a search for shoes on Google will turn up lots of stuff like this.
![Page 4: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/4.jpg)
OMG! SHOES!
x-platform GUI in Ruby!4
We’re talking about Shoes, a cross-platform framework for making GUI apps, using the Ruby language.
![Page 5: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/5.jpg)
_why_ ruby?
• Highly dynamic
• Very high level
• 100% object oriented
• 100% open-source
5
It’s also incredibly easy to learn.
![Page 6: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/6.jpg)
data types in ruby
6
One of the nice things about Ruby is that it strives to be easy to read. Here, we’re declaring some variables and setting values.
![Page 7: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/7.jpg)
variablesConstants
Local variable
Instance variable
7
Like most languages, you’ve got constants, local variables, and instance variables. The convention in Ruby is to use all capital letters for constants, but anything that starts with a capital letter is considered constant.
You can actually change values of constants at runtime, but you will get a warning about that.
Instance variables get the @ sign.
![Page 8: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/8.jpg)
Ruby is dynamically typed
8
Anyone know what dynamically typed is?
What’s the opposite of dynamically typed?
![Page 9: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/9.jpg)
don’t confuse that with weak typed!
9
![Page 10: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/10.jpg)
a type can be defined explicitly
10
![Page 11: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/11.jpg)
or implicitly
11
![Page 12: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/12.jpg)
...but a string and a number can’t just be
mashed together without help.
12
![Page 13: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/13.jpg)
bad
13
You’ll get a runtime error because you can’t add a string to a number
![Page 14: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/14.jpg)
better
14
The to_s method converts many types of objects to strings.
![Page 15: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/15.jpg)
awesome.
#{} embeds an expression in a string,
converting the result to a string!
15
You can embed any expression this way and it will automatically cast the value to a string, even if it’s a null value.
![Page 16: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/16.jpg)
you’re going to see#{}
a lot.
16
![Page 17: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/17.jpg)
ruby has simple logic
17
![Page 18: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/18.jpg)
defining methods
18
def is so much nicer than function.
![Page 19: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/19.jpg)
ruby has some simple rules
19
![Page 20: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/20.jpg)
everything isan object
20
There’s no such thing as a primitive in Ruby. Even a string or an integer is an object.
![Page 21: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/21.jpg)
every statement returns a value.
21
With methods, if it’s not explicit with a return, then the return value is the value of the last statement.
![Page 22: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/22.jpg)
everything evaluatesto TRUE exceptnil and FALSE.
22
1 is true. 0 is not false.
![Page 23: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/23.jpg)
everything is an object.everything is a class.
classes can be boring or awesome.
23
![Page 24: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/24.jpg)
booooooring
24
The “java” way. This is on the way out because it’s stupid. Here we’re declaring instance variables, getters, and setters. Essentially creating properties.
![Page 25: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/25.jpg)
awesome.
25
attr_accessor creates variables, getters, and setters.
![Page 26: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/26.jpg)
as you write rubyyou often see codethat writes code.
26
Metaprogramming!
![Page 27: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/27.jpg)
arrays and hashes are important. Pay attention.
27
They’re everywhere.
![Page 28: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/28.jpg)
arrays
28
Square brackets denote hashes.
![Page 29: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/29.jpg)
hash
29
Curly braces and => are for hashes.
![Page 30: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/30.jpg)
whenever you see
=>
you’re dealing with a hash.
30
Hashrocket.
![Page 31: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/31.jpg)
methods that take hashes as parameters
are very, very common.
31
![Page 32: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/32.jpg)
this method takes one parameter.
32
Only one parameter which is a hash. Hashes are amazing because you can actually send the parameters into a method in any order, and it’s nicely self-documenting. No referencing the api to figure out which parameter is the width.
![Page 33: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/33.jpg)
now let’stake a walk
around the Block
33
Blocks are like closures or anonymous fuctions
![Page 34: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/34.jpg)
blocks let us loop
34
We can use them for looping instead of having to track an array or hash position.
![Page 35: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/35.jpg)
so, a regular class...
35
![Page 36: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/36.jpg)
...can be improved with blocks
36
This is a standard pattern in Ruby classes.
![Page 37: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/37.jpg)
37
Obligatory LOLCAT is obligatory!
![Page 38: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/38.jpg)
make constructors accept hashes...
38
![Page 39: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/39.jpg)
...and use a block toiterate over keys and
values to assign instance variables.
39
![Page 40: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/40.jpg)
this technique makes writing DSLs
easy.
40
![Page 41: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/41.jpg)
no. wrong.
41
![Page 42: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/42.jpg)
DomainSpecific
Language
42
![Page 43: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/43.jpg)
ruby has “sugar” tomake it easy to read.
43
Parenthesis are optional in many cases, especially when it’s obvious.
![Page 44: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/44.jpg)
oh yeah...
= is assignment.
== is equality.
44
![Page 45: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/45.jpg)
ok now you’re warmed up.
45
![Page 46: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/46.jpg)
but you have to Tie your Shoes
before you can run!
46
you’re supposed to BOO!
![Page 47: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/47.jpg)
47
and no, this doesn’t excuse the bad joke.
![Page 48: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/48.jpg)
Shoes is a DSL.
48
![Page 49: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/49.jpg)
a Shoes app is a ruby object.
49
![Page 50: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/50.jpg)
your code lives inside of this object using blocks.
50
![Page 51: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/51.jpg)
it’s super easy.
51
![Page 52: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/52.jpg)
REALLY super easy.
52
![Page 53: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/53.jpg)
so, basic stuff.
53
![Page 54: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/54.jpg)
Shoes.app
54
![Page 55: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/55.jpg)
background
55
![Page 56: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/56.jpg)
background
56
![Page 57: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/57.jpg)
backgrounds can usehex codes too.
57
![Page 58: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/58.jpg)
layout works likeyou wish HTML and CSS works
58
![Page 59: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/59.jpg)
stacks
59
![Page 60: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/60.jpg)
all sub elements stack.
60
![Page 61: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/61.jpg)
flows
61
![Page 62: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/62.jpg)
all sub elements flow
62
![Page 63: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/63.jpg)
combine stacksand flows
to make complexlayouts
63
![Page 64: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/64.jpg)
two column with header
64
![Page 65: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/65.jpg)
the Shoes window is also
a flow.
65
![Page 66: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/66.jpg)
simple text
66
![Page 67: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/67.jpg)
edit_line
67
![Page 68: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/68.jpg)
edit_line
great for passwordz
68
![Page 69: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/69.jpg)
edit_box
69
![Page 70: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/70.jpg)
list_box
arrays and hashes are everywhere.
70
![Page 71: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/71.jpg)
radio
71
![Page 72: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/72.jpg)
check
72
![Page 73: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/73.jpg)
use instance variablesto reference controls.
73
![Page 74: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/74.jpg)
grabbing and showing input
74
Use the .text method to grab the text from the textbox.
![Page 75: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/75.jpg)
any object is fair game.even stacks and floats
75
![Page 76: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/76.jpg)
append to a stack
76
The @names section contains the names we add, and names get added when we click the button.
![Page 77: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/77.jpg)
Clearing a stack
77
Stacks and flows can be cleared as well. Clear can take a block which you can use to place new content in the stack or flow.
![Page 78: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/78.jpg)
Windows
78
![Page 79: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/79.jpg)
windows arelike new apps.
79
So instance variables are isolated.
![Page 80: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/80.jpg)
each screenis a url.
80
![Page 81: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/81.jpg)
urls and methods
81
We can use a nice MVC-style structure here. Notice that we can wrap blocks in methods so we can easily call them.
![Page 82: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/82.jpg)
shoes canplay music
and movies...
82
The video player plays mp3s, oggs, avis, movs, flvs and more.
![Page 83: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/83.jpg)
load images...
83
![Page 84: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/84.jpg)
...and open URLs in browsers.
84
![Page 85: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/85.jpg)
you can use any gemwith Shoes.
85
There are hundreds of libraries out there for doing pretty much anything. Twitter, Youtube, Flickr, Last.fm, and anything in between.
![Page 86: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/86.jpg)
shoes can installlibraries for you.
86
When the app starts, these libraries get installed to the user’s home directory.
![Page 87: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/87.jpg)
you can alsoaccess OS stuff.
87
![Page 88: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/88.jpg)
88
Accessing standard dialogs and the clipboard is pretty simple.
![Page 89: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/89.jpg)
demos
89
![Page 90: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/90.jpg)
http://github.com/napcs/shoes_demo_apps/
90
Either check it out with git or click the download link and unzip the package.
![Page 91: learning to walk in shoesblog.napcs.com/wp-content/uploads/2009/05/tccc_vi_shoes.pdf · you often see code that writes code. 26 Metaprogramming! arrays and hashes are important. Pay](https://reader034.vdocuments.us/reader034/viewer/2022043009/5f9d7d12e759f961b7610397/html5/thumbnails/91.jpg)
twitter: bphogan
http://www.napcs.com/
91