hackety_hack-lessons 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/content/ruby.md ADDED
@@ -0,0 +1,332 @@
1
+ # Beginner Ruby
2
+
3
+ ## Hello there!
4
+
5
+ ### Let's get started
6
+
7
+ Welcome to your first lesson in Ruby! You're going to have a blast.
8
+
9
+ Ruby is a great programming language that you can use to make all kinds of
10
+ things with. Let's get going!
11
+
12
+ Click the icon like this (on the bottom of the screen) to get started:
13
+
14
+ ![Not this one! The one below!](/icon_button/arrow_right)
15
+
16
+ ### Lesson Controls
17
+
18
+ Before we move on, Here's a refresher on the controls you can use to move around
19
+ in the Lesson.
20
+
21
+ ![](/icon_button/arrow_left)
22
+ __back__: goes back one page
23
+
24
+ ![](/icon_button/arrow_right)
25
+ __continue__: goes to the next page
26
+
27
+ ![](/icon_button/menu)
28
+ __menu__: makes it easy to jump around to any lesson
29
+
30
+ ![](/icon_button/x)
31
+ __close__: closes the tutor
32
+
33
+ Don't forget! Press this to move to the next part:
34
+
35
+ ![](/icon_button/arrow_right)
36
+
37
+ Have at it!
38
+
39
+ ## A bit more about Ruby
40
+
41
+ ### Konnichiwa, Ruby!
42
+
43
+ _Ruby_ was created by
44
+
45
+ まつもと ゆきひろ
46
+
47
+ (you can just call him Matz) in 1995. If you couldn't guess, Matz is from
48
+ Japan. Here he is:
49
+
50
+ ![](static/matz.jpg)
51
+
52
+ ### Ruby is enjoyable
53
+
54
+ Matz has this to say about Ruby:
55
+
56
+ _I hope to see Ruby help every programmer in the world to be productive, and to
57
+ enjoy programming, and to be happy. That is the primary purpose of Ruby
58
+ language._
59
+
60
+ One more thing about Ruby: Rubyists (that's what people who like Ruby call
61
+ themselves) have a saying: __MINSWAN__. This stands for __M__atz __I__s __N__ice
62
+ __S__o __W__e __A__re __N__ice. Which is a pretty nice saying, itself. Be nice
63
+ to everyone, and give them a hand when they need it!
64
+
65
+ ## Displaying Things
66
+
67
+ ### Let's do this!
68
+
69
+ Okay! The very first thing that you need to know is how to show something on the
70
+ screen. Otherwise, you won't know what's going on!
71
+
72
+ In order to start coding, we need to bring up the Editor. Its icon looks like
73
+ this:
74
+
75
+ ![Not this one, silly! the one on the left!](static/tab-new.png)
76
+
77
+ Click the icon to open the Editor up, and then we'll move on...
78
+
79
+ ### Hello, World!
80
+
81
+ There are two ways of doing this. Here's the first: alert
82
+
83
+ alert "Hello, world!"
84
+
85
+ Type this in and press the 'Run' button.
86
+
87
+ ### alert
88
+
89
+ Okay, let's break this down: There's two main parts to this little program: you
90
+ have an `alert`, and a `"Hello, world!"`. These two parts work just like an
91
+ English sentence: The `alert` is a verb and the stuff in the ""s is an object.
92
+ In Ruby, we call verbs __methods__. The `alert` verb says 'Put an alert box on
93
+ the screen, and the content of the box is whatever thing you give me.'
94
+
95
+ We'll talk about the `"Hello, world!"` in just a second. Here's the other way of
96
+ making this happen:
97
+
98
+ puts "Hello, world!"
99
+
100
+ But if you try that here, it won't work! The `puts` method doesn't display a
101
+ dialog box, it puts text out to a command-line prompt. Since Hackety Hack is all
102
+ graphical, this doesn't work here. So we'll be using `alert`s throughout these
103
+ tutorials, but if you look at other Ruby tutorials, you may see `puts`.
104
+
105
+ ## Letters, words, and sentences
106
+
107
+ ### Strings
108
+
109
+ Okay! Now that you've got that verb bit down, it's time to learn about
110
+ _String_s. Strings are what we call a bunch of words between a pair of "
111
+ characters. The "s are used to tell the computer what words you actually want to
112
+ say. Let's think about our example:
113
+
114
+ alert "Hello, world!"
115
+
116
+ If you didn't have the "s, the computer wouldn't know which words were methods
117
+ and which ones were part of the string! And consider this:
118
+
119
+ alert "I am on high alert!"
120
+
121
+ Without making all of those words a string, how would Ruby know that the second
122
+ alert was some text you wanted to say, rather than another alert box?
123
+
124
+ ### Adding Strings
125
+
126
+ Now, if you want to put two bits of strings together, you can use the `+`
127
+ character to do it. Try typing this:
128
+
129
+ alert "Hello, " + "world!"
130
+
131
+ Same thing! The `+` sticks the two strings together. This will end up being
132
+ super useful later!
133
+
134
+ ## Numbers and Math
135
+
136
+ ### Numbers
137
+
138
+ You can just use numbers, and Ruby understands them:
139
+
140
+ alert 2
141
+
142
+ You can even use numbers that have a decimal point in them:
143
+
144
+ alert 1.5
145
+
146
+ ### Basic Math
147
+
148
+ You can also do math with numbers, and it'll work out pretty well:
149
+
150
+ alert 1 + 2
151
+ alert 5 - 3
152
+ alert 2 * 3
153
+ alert 4 / 2
154
+
155
+ But if you try this, nothing happens:
156
+
157
+ alert "hey" + 2
158
+
159
+ This is kind of fun and silly, though:
160
+
161
+ alert "hey" * 2
162
+
163
+ ### Errors
164
+
165
+ You know how nothing happened when you hit the Run button earlier? That was
166
+ because there was an error. You can see any errors that run by hitting either
167
+ Alt-/ or Command-/, depending on what kind of computer you're using.
168
+
169
+ The error that results from `alert "hey" + 2` is
170
+
171
+ can't convert Fixnum into String
172
+
173
+ What is that?
174
+
175
+ ## A few words about types
176
+
177
+ ### Why's it do that?
178
+
179
+ Each part of a Ruby program is an `Object`. Right now, all you need to know
180
+ about `Object`s is that it's sort of like saying "a thing." Your program is made
181
+ up of a bunch of `Object`s working together.
182
+
183
+ We'll learn more about `Object`s in a future lesson, but there is one thing I'll
184
+ tell you: `Object`s have a 'type.' This lets Ruby know what kind of `Object` it
185
+ is.
186
+
187
+ ### Adding numbers to words
188
+
189
+ That's why
190
+
191
+ alert "hey" + 2
192
+
193
+ doesn't really work: "hey" is a `String` object, and 2 is a `Fixnum` object. And
194
+ adding `String`s and `Fixnum`s doesn't make any sense. We can make this code
195
+ work, though!
196
+
197
+ All we need to do is turn the `Fixnum` into a `String`. We can do this by using
198
+ the `to_s` method.
199
+
200
+ alert "hey" + 2.to_s
201
+
202
+ ### Let's look at that again
203
+
204
+ alert "hey" + 2.to_s
205
+
206
+ Okay, this isn't bad. We have our `alert` method. We're giving it `"hey" +
207
+ 2.to_s`. The `2.to_s` turns a `Fixnum` 2, which is like the mathematical idea of
208
+ a 2, into the `String` 2, which is like when you write a 2 down on a piece of
209
+ paper.
210
+
211
+ ## Variables
212
+
213
+ ### They're like boxes
214
+
215
+ What happens if we want to keep something around? Most programs are not one
216
+ line, I assure you. You can use a _variable_ to hold a value and use it later.
217
+ It's like a box that you put things in.
218
+
219
+ Let's try one out:
220
+
221
+ message = "Hello, world!"
222
+ alert message
223
+
224
+ Give that a run.
225
+
226
+ ### Assignment
227
+
228
+ Cool stuff! We used an `=` to _assign_ the `String`"Hello, world!" into the
229
+ variable `message`. We then passed that `message` to the `alert` method.
230
+
231
+ As you can see, we can use variables in place of another value. Try this:
232
+
233
+ number = 5
234
+ number = number * 2
235
+ number = number - 8
236
+ number = number + 1
237
+ alert number
238
+
239
+ Make a guess before you run this program.
240
+
241
+ ## User Input
242
+
243
+ ### ask-ing for it.
244
+
245
+ We can ask the user of our program for some input, and then put their answer
246
+ into a variable. It's easy! Check this program out:
247
+
248
+ name = ask "What is your name?"
249
+ alert "Hello, " + name
250
+
251
+ The `ask` method brings up a box and lets our users type something in. Fun! We
252
+ put their answer into the `name` variable and then showed it with `alert`.
253
+ Sweet!
254
+
255
+ ## Basic flow control
256
+
257
+ ### if...
258
+
259
+ Remember back to that Beginning Programming lesson... we talked about how
260
+ programs are one big list, that the computer follows in order.
261
+
262
+ Well, guess what? We can actually change this order by using certain bits of
263
+ code. Compare these two programs:
264
+
265
+ number = 2
266
+ if number == 2
267
+ alert "Yes!"
268
+ else
269
+ alert "No!"
270
+ end
271
+
272
+ number = 1
273
+ if number == 2
274
+ alert "Yes!"
275
+ else
276
+ alert "No!"
277
+ end
278
+
279
+ There are a few new things here.
280
+
281
+ ### ==
282
+
283
+ Here it is again:
284
+
285
+ number = 2
286
+ if number == 2
287
+ alert "Yes!"
288
+ else
289
+ alert "No!"
290
+ end
291
+
292
+ The == command is just a bit different than the = command. == tests the `Object`
293
+ on its right against the `Object` on its left. If the two are equal, then the
294
+ code after the `if` will run. If they're not equal, you get the code after the
295
+ `else`. The `end` lets us know we're done with our `if`.
296
+
297
+ ## Example: a guessing game
298
+
299
+ ### Guess!
300
+
301
+ Let's put this all together:
302
+
303
+ ```
304
+ secret_number = 42.to_s
305
+ guess = ask "I have a secret number. Take a guess, see if you can figure it out!"
306
+ if guess == secret_number
307
+ alert "Yes! You guessed right!"
308
+ else
309
+ alert "Sorry, you'll have to try again."
310
+ end
311
+ ```
312
+
313
+ Can you guess what `to_s` does, and why you need it? If you're stumped, try
314
+ asking [on the Hackety Hack site](http://hackety-hack.com/stream) and we'll give
315
+ you a hand.
316
+
317
+ ## Summary
318
+
319
+ ### Good job!
320
+
321
+ Congrats! You've picked up all of the basics of Ruby. There's a lot more you
322
+ still have to learn, though!
323
+
324
+ Here's what you've learned so far:
325
+
326
+ `alert` and `ask`
327
+
328
+ `=`, variables, and `==`
329
+
330
+ `if` and `else`
331
+
332
+ Awesome! You'll want to check out Basic Shoes next!
data/content/shoes.md ADDED
@@ -0,0 +1,208 @@
1
+ # Beginner Shoes
2
+
3
+ ## Hello there!
4
+
5
+ ### Let's get started
6
+
7
+ Welcome to your first lesson about Shoes! I'm going to introduce you to the
8
+ basics that Shoes brings to everyone who programs.
9
+
10
+ If you didn't know, Shoes is a Ruby toolkit that lets you build GUI programs
11
+ really easy and fun!
12
+
13
+ Click the icon like this (on the bottom of the screen) to get started:
14
+
15
+ ![Not this one! The one below!](/icon_button/arrow_right)
16
+
17
+ ### Lesson Controls
18
+
19
+ Before we move on, Here's a refresher on the controls you can use to move around
20
+ in the Lesson.
21
+
22
+ ![](/icon_button/arrow_left)
23
+ __back__: goes back one page
24
+
25
+ ![](/icon_button/arrow_right)
26
+ __continue__: goes to the next page
27
+
28
+ ![](/icon_button/menu)
29
+ __menu__: makes it easy to jump around to any lesson
30
+
31
+ ![](/icon_button/x)
32
+ __close__: closes the tutor
33
+
34
+ Don't forget! Press this to move to the next part:
35
+
36
+ ![](/icon_button/arrow_right)
37
+
38
+ Have at it!
39
+
40
+ ## Apps
41
+
42
+ ### Shoes.app
43
+
44
+ Okay! Shoes is tons of fun. It's really easy to get started. Here's the simplest
45
+ Shoes app ever:
46
+
47
+ Shoes.app do
48
+ end
49
+
50
+ Give that a spin!
51
+
52
+ ### It's just a block
53
+
54
+ You didn't say that you wanted anything in the app, so it just gives you a blank
55
+ window. You can pass options in, too:
56
+
57
+ Shoes.app :height => 200, :width => 200 do
58
+ end
59
+
60
+ This'll give you whatever sized app you want! We'll be putting all of the fun
61
+ stuff inside of the `do...end`.
62
+
63
+ ## para
64
+
65
+ ### The basics
66
+
67
+ Blank windows are pretty boring, so let's spice it up with some text!
68
+
69
+ Shoes.app do
70
+ para "Hello, world"
71
+ end
72
+
73
+ You know what to do by now. `para` is short for 'paragraph.' It lets you place
74
+ text in your apps.
75
+
76
+ `para` and other Shoes widgets take bunches of options, too. Check it:
77
+
78
+ Shoes.app do
79
+ para "Hello there, world", :font => "TakaoGothic"
80
+ end
81
+
82
+ ## stacks
83
+
84
+ ### They're default!
85
+
86
+ If you're looking to lay out your Shoes widgets, there are two options. The
87
+ first is a `stack`. A Stack is the default layout a Shoes app has. So this won't
88
+ look much differently than one without the stack:
89
+
90
+ Shoes.app do
91
+ stack do
92
+ para "Hello!"
93
+ para "Hello!"
94
+ para "Hello!"
95
+ end
96
+ end
97
+
98
+ As you can see, the `para`s are stacked on top of each other. By itself, kinda
99
+ boring, since they already do this. But...
100
+
101
+ ## flows
102
+
103
+ ### The counterpart of stacks
104
+
105
+ `flow`s are kind of like stacks, but they go sideways rather than up and down.
106
+ Try this as an example:
107
+
108
+ Shoes.app do
109
+ flow do
110
+ para "Hello!"
111
+ para "Hello!"
112
+ para "Hello!"
113
+ end
114
+ end
115
+
116
+ Just a little bit different, eh?
117
+
118
+ ## stacks + flows
119
+
120
+ ### With their powers combined...
121
+
122
+ You can combine the `stack` with the `flow`s to make whatever kind of layout you
123
+ want. For example:
124
+
125
+ Shoes.app do
126
+ flow do
127
+ stack :width => 50 do
128
+ para "Hello!"
129
+ para "Hello!"
130
+ para "Hello!"
131
+ end
132
+ stack :width => 50 do
133
+ para "Goodbye!"
134
+ para "Goodbye!"
135
+ para "Goodbye!"
136
+ end
137
+ end
138
+ end
139
+
140
+ The `:width` attribute sets how wide the stack is. Pretty simple.
141
+
142
+ ## button
143
+
144
+ ### Push it real good
145
+
146
+ Buttons are also super simple in Shoes. Just give them a title and a bunch of
147
+ code to run when they get pushed:
148
+
149
+ Shoes.app do
150
+ button "Push me" do
151
+ alert "Good job."
152
+ end
153
+ end
154
+
155
+ I bet you're starting to see a pattern. Shoes loves to use blocks of code to
156
+ make things super simple.
157
+
158
+ ## image
159
+
160
+ ### Pics or it didn't happen
161
+
162
+ There are two ways that you can show an image in a Shoes app. Either you have
163
+ the file on your computer:
164
+
165
+ Shoes.app do
166
+ image "#{HH::STATIC}/matz.jpg"
167
+ end
168
+
169
+ (Can you figure out what this does? Don't feel bad if you can't.)
170
+
171
+ You can also specify an image on the web:
172
+
173
+ Shoes.app do
174
+ image "http://shoesrb.com/images/shoes-icon.png"
175
+ end
176
+
177
+ Either one is fine. Shoes cares not.
178
+
179
+ ## edit_line
180
+
181
+ ### Getting some input
182
+
183
+ If you'd like to let someone type something in a box, well, `edit_line` is right
184
+ up your alley!
185
+
186
+ Shoes.app do
187
+ edit_line
188
+ end
189
+
190
+ This is sort of boring though... why not get the information from the box?
191
+
192
+ Shoes.app do
193
+ line = edit_line
194
+ button "Push me!" do
195
+ alert line.text
196
+ end
197
+ end
198
+
199
+ ## Summary
200
+
201
+ ### Great job!
202
+
203
+ There's a ton more things that you can do with Shoes, but you've got the basics
204
+ down!
205
+
206
+ If you'd like to learn more, you can visit the [Shoes
207
+ website](http://shoesrb.com/) or press Control-M (or Command-M) to bring up the
208
+ Shoes Manual.