forked from cherimarie/gdi-ruby
/
class1.html
458 lines (447 loc) · 17.3 KB
/
class1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Intro to Ruby ~ Girl Develop It</title>
<meta name="description"
content="This is the official Girl Develop It Core Intro to Ruby course. The course is meant to be taught in four two-hour sessions. Each of the slides and practice files are customizable according to the needs of a given class or audience.">
<meta name="author" content="Girl Develop It">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
<link rel="stylesheet" href="reveal/css/reveal.css">
<link rel="stylesheet" href="reveal/css/theme/gdisunny.css" id="theme">
<link rel="stylesheet" href="reveal/lib/css/dark.css">
<!-- If use the PDF print sheet so students can print slides-->
<link rel="stylesheet" href="reveal/css/print/pdf.css" type="text/css" media="print">
</head>
<body>
<div class="reveal">
<div class="slides">
<!-- Welcome & Intros - 20 min -->
<section>
<img src="images/gdi_logo_badge.png">
<h3>Intro to Ruby</h3>
<h4>Class 1</h4>
</section>
<section>
<h3>Welcome!</h3>
<div>
<p>Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.</p><br>
<p class="blue">Some "Rules":</p>
<ul>
<li>We are here for you!</li>
<li>Every question is important.</li>
<li>Help each other.</li>
<li>Have fun!</li>
</ul>
</div>
</section>
<section>
<h3>Welcome!</h3>
<div>
<p class = "blue">Tell us about yourself.</p>
<ul>
<li>Who are you?</li>
<li>What do you hope to get out of this class?</li>
<li>What is your favorite ice cream or frozen dessert?</li>
</ul>
</div>
</section>
<!-- Setting the Stage - 10 min -->
<section>
<h3>What we will cover today</h3>
<ul>
<li class="fragment">What is programming?</li>
<li class="fragment">Why Ruby?</li>
<li class="fragment">Variables, Arithmetic & Objects</li>
<li class="fragment">Methods and Error Messages</li>
</ul>
</section>
<section>
<h3>What is programming?</h3>
<ul>
<li class="fragment">Teaching the computer to do a task.</li>
<li class="fragment">A program is made of one or more files of code, each of which solve part of the overall task.
</li>
<li class="fragment">Programming code is human readable but also needs a form that the computer can run directly.
This form is not human readable.
</li>
<!--<li class="fragment">To create the form of code the computer can use, we use the Ruby <a-->
<!--href="http://en.wikipedia.org/wiki/Interpreter_(computing)">interpreter</a>. Other languages use other-->
<!--interpreters or a <a href="http://en.wikipedia.org/wiki/Compiler">compiler</a>-->
<!--</li>-->
<!--<li class="fragment">Don't focus on what's "under the hood" for now. We will "drive the car" first.</li>-->
<!--<li class="fragment">In other words, there are many layers to the onion. We start at one layer and slowly move-->
<!--toward layers that are beneath or above us.-->
<!--</li>-->
</ul>
</section>
<section>
<h3>Why Ruby?</h3>
<ul>
<li class="fragment">It reads like English. The syntax is intuitive.</li>
<pre>
<code contenteditable class="ruby fragment">
# Java
for(int i = 0; i < 5; i++)
# Ruby
5.times do
</code>
</pre>
<li class="fragment">The community is large, active and interested in helping others learn.</li>
<li class="fragment">You can get a web app off the ground quickly.</li>
<!--<li class="fragment">You can make a lucrative career out of it.</li>-->
<!--<li class="fragment">Using Ruby will cost you $0.</li>-->
</ul>
</section>
<section>
<h3>What is Ruby used for?</h3>
<ul>
<li class="fragment">Web development (Rails)</li>
<li class="fragment">iPhone apps (RubyMotion)</li>
<li class="fragment">System Administration (Chef)</li>
<li class="fragment">Testing (Vagrant)</li>
<li class="fragment">Security (Metasploit)</li>
</ul>
</section>
<section>
<h3>Who is using Ruby?</h3>
<ul>
<li>Groupon</li>
<li>Airbnb</li>
<li>Shopify</li>
<li>Soundcloud</li>
<li>Basecamp</li>
<li>Github</li>
<li>More <a href="https://www.ruby-lang.org/en/documentation/success-stories/">Success Stories</a></li>
</ul>
</section>
<!-- Using a REPL - 10 min -->
<section>
<h3>Working with a Repl</h3>
<ul>
<li class="fragment">Repl stands for: Read, Evaluate, Print, Loop. It's an interactive programming environment where you can write and execute code. Using a Repl is great way to get started quickly, as you don't need to install anything to get started.
</li>
<li class="fragment">Open a browser and go to: <a href="https://repl.it/">repl.it</a></li>
<li class="fragment">In the dropdown, choose Ruby.</li>
<li class="fragment">Follow along with the examples in the slides. Type them in!</li>
</ul>
</section>
<section>
<h3>Arithmetic</h3>
<p>Try out some calculator functions</p>
<pre>
<code contenteditable class="ruby">
3 + 4
2 * 4
6 - 2
4 / 2
4 /* 2
=> SyntaxError: (irb):10:syntax error, unexpected *
</code>
</pre>
</section>
<section>
<h3>Errors are Neat!</h3>
<ul>
<li class="fragment">There are different kinds of errors that can occur. We just saw the <strong>SyntaxError</strong> which often
helps us find misspelled words or missing quotes.
</li>
<li class="fragment">Take time to read each Error. They often tell you how to fix the issue and can be a great
starting point when searching for help online.
</li>
</ul>
</section>
<!-- Variables - 10 min -->
<section>
<h3>Variables</h3>
<ul>
<li class="fragment">Variables are references to information.</li>
<li class="fragment">We reference variables by name.</li>
<li class="fragment">They are called variable because the information they reference may change.</li>
</ul>
<pre><code contenteditable class="ruby fragment">
# Everything after this pound/hash sign will not be evaluated.
# These are called comments and I will use them to annotate code
age = 50
days_in_year = 365
days_alive = age * days_in_year
=> 18250
</code></pre>
</section>
<section>
<h3>Ruby's Variables</h3>
<ul>
<li class="fragment">Ruby has three kinds of variables, one kind of constant and exactly two pseudo-variables.</li>
<li class="fragment">A local variable starts with a lower case letter or an underscore character and consists entirely of letters, numbers and underscores.</li>
</ul>
<pre><code contenteditable class="ruby fragment">
age = 50
_age = 50
_my_age = 50
</code></pre>
</section>
<section>
<h3>What can I do with a Variable?</h3>
<ul>
<li class="fragment">Create - Initialize</li>
<li class="fragment">Access - Read</li>
<li class="fragment">Assign - Replace</li>
</ul>
<pre><code contenteditable class="ruby fragment">
# create and assign in one line
age = 0
# access the value in age
age
# replace value in age
age = 40
</code></pre>
</section>
<section>
<h3>Variable naming</h3>
<ul>
<li class="fragment">Express what is stored inside</li>
<li class="fragment">Make it easy to read</li>
<li class="fragment">Should be understood by someone who has no idea what your program does</li>
<li class="fragment">Should be unique</li>
</ul>
<pre><code contenteditable class="ruby fragment">
# good
occupation = "software engineer"
# bad
occupation_i_always_dreamed_of_having_in_seattle = "software engineer"
o = "software engineer"
1st_occupation = "software engineer"
</code></pre>
</section>
<section>
<h3>Local Variable Values</h3>
<ul>
<li class="fragment">No default value</li>
<li class="fragment">No type declaration</li>
<li class="fragment">Do not live forever</li>
</ul>
<pre><code contenteditable class="ruby fragment">
# error
name
name = "Jess"
defined?(name)
</code></pre>
</section>
<!-- Data Types - 10 min -->
<section>
<h2>Data Types</h2>
<ul>
<li class="fragment">Numbers, Strings, Symbols, Booleans, Regular Expressions, Arrays, Ranges & Hashes</li>
<li class="fragment">Data always has a "type"</li>
<li class="fragment">You will hear the words Class/Type/Object used interchangeably</li>
</ul>
<pre><code contenteditable class="ruby fragment">
irb> 1.class
=> Integer
irb> 1.0022.class
=> Float
irb> "Hello".class
=> String
irb> [1, 2, 3].class
=> Array
</code></pre>
</section>
<section>
<h3>Strings</h3>
<p>Strings are characters inside double or single quotes.</p>
<pre><code contenteditable class="ruby fragment">
first_string = 'Hello '
second_string = "World"
combined_string = first_string + second_string
combined_string.reverse
=> "dlroW olleH"
</code></pre>
<pre><code contenteditable class="ruby fragment">
name = "Jessica "
name_multiple = name * 4
# Here multiplying a by 4 concatenates (links) four strings together
=>"Jessica Jessica Jessica Jessica "
</code></pre>
</section>
<section>
<h3>String Practice</h3>
<pre><code contenteditable class="ruby">
name = "Jessica"
name.upcase
name.downcase
name.capitalize
name.length
name.swapcase
"".empty?
</code></pre>
<p>What is the reverse of your name?</p>
<p>How many characters long is your name?</p>
<p>Can you repeat the word hello 100 times?</p>
<p>What is the 5th character of my name (or your name)?</p>
</section>
<section>
<h3>Numbers</h3>
<p>Numeric data comes in two types: <strong>Integers</strong> and <strong>Floats</strong></p>
<p>Integers do not have decimals.</p>
<p>Floats are numbers with at least one number to the left of a decimal point.</p>
<pre><code contenteditable class="ruby fragment">
irb> 55.class
=> Integer
irb> 55_000.class
=> Integer
irb> 55.001.class
=> Float
</code></pre>
</section>
<section>
<h3>Number Practice</h3>
<pre><code contenteditable class="ruby">
7/8
7.0/8.0
3.14.to_s
1 + "2"
(1 + 2) * 3
1 + (2 * 3)
</code></pre>
<p>What is the number 1.25976 rounded to a precision of 2?</p>
<p>What is the the smallest possible integer that is greater than or equal to 5.2?</p>
<p>How would you turn the number 42 into a float? How would you turn the float 56.25 into an integer?</p>
</section>
<section>
<h3>Symbols</h3>
<p class="fragment">You can think of symbols as lightweight Strings.</p>
<p class="fragment">It's good to know these exist, but don't worry about them too much for now.</p>
<pre><code contenteditable class="ruby fragment">
# transient and mutable
"hello"
# permanent and immutable
:hello
</code></pre>
</section>
<section>
<h3>Booleans</h3>
<p class="fragment">This is another Object that we will learn about later.</p>
<p class="fragment">For now, when you hear Boolean, think TRUE and FALSE.</p>
<pre><code contenteditable class="ruby fragment">
# NOT true
!true
=> false
# NOT false
!false
=> true
</code></pre>
</section>
<section>
<h3>Arrays, Ranges & Hashes</h3>
<p>We will also leave these data types for the next class</p>
<p class="fragment">Examples of what they will look like:</p>
<pre><code contenteditable class="ruby fragment">
# Arrays are used to hold sets of data.
irb> array_of_numbers = [1,2,3]
irb> array_of_numbers.first
=> 1
# Ranges are used to express a sequence.
irb> range_of_numbers = (1..5)
irb> range_of_numbers.include?(4)
=> true
# Hashes are like dictionaries. You can look up a value by a key.
irb> hash_of_key_to_value =
{
"Apple" => "A fruit.",
"Cucumber" => "A vegetable."
}
</code></pre>
</section>
<section>
<h3>Methods</h3>
<ul>
<li class="fragment">Methods define the behavior for an Object.</li>
<li class="fragment">String Objects can <strong>reverse</strong>, for example.</li>
<li class="fragment">Some methods are accessed using our friend 'dot' and some are standalone.</li>
</ul>
<pre>
<code contenteditable class="ruby fragment">
irb> "2".to_i
=> 2
irb> 2.to_s
=> "2"
irb> "2" / 5
NoMethodError: undefined method `/' for "2":String
</code>
</pre>
</section>
<section>
<h3>User Input</h3>
<p class="fragment">To obtain user input, use the `gets` keyword</p>
<p class="fragment">To print out information, use the `puts` or `print` keyword</p>
<p class="fragment">Let's create our first Ruby program together!</p><br>
<p class="fragment">Put the code below in your repl and run it! What's happening on each line?</p>
<pre><code contenteditable class="fragment ruby">
puts "Hello there, and what's your name?"
name = gets.chomp!
puts "Your name is " + name + "? What a lovely name!"
puts "Pleased to meet you, " + name + ". :)"
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<ul>
<li>Write your own program using 'puts' and 'gets' to ask a user for their age and then tell them how old they are in dog years.</li>
<li>reminder: 'gets' method returns a string. To do math on it, convert it to an integer with `.to_i` method.</li>
<pre><code class="ruby">
#1 dog year = 7 human years
user_age = gets.to_i
</code></pre>
</ul>
</section>
<section>
<h3>Homework</h3>
<p><strong>Practice:</strong> Write a command line program that asks the user for the year they were born, then calculates their age in years, days, and seconds. Tell the user how old they are in these different formats. (Note: you'll be using 'gets' and 'puts' in this program, along with some math)</p><br>
<p><strong>Prep:</strong> Read <a href="https://pine.fm/LearnToProgram/?Chapter=06" alt="Chp 6 of Learn to Program">Chapter 6</a> and <a href="https://pine.fm/LearnToProgram/?Chapter=07" alt="Chp 7 of Learn to Program">Chapter 7</a> of Learn To Program- don't try to do the exercises at the end yet, though.</p><br>
<p><strong><a href="https://github.com/gdiseattle/gdi-ruby/blob/master/ruby-installfest-instructions.md">Install Ruby</a></strong>
</section>
</div>
<footer>
<div class="copyright">
Intro to Ruby ~ Girl Develop It ~
<a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/deed.en_US"><img alt="Creative Commons License" src="http://i.creativecommons.org/l/by-nc/3.0/80x15.png"/></a>
</div>
</footer>
</div>
<script src="reveal/lib/js/head.min.js"></script>
<script src="reveal/js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'reveal/lib/js/classList.js', condition: function () {
return !document.body.classList;
} },
{ src: 'reveal/plugin/markdown/showdown.js', condition: function () {
return !!document.querySelector('[data-markdown]');
} },
{ src: 'reveal/plugin/markdown/markdown.js', condition: function () {
return !!document.querySelector('[data-markdown]');
} },
{ src: 'reveal/plugin/highlight/highlight.js', async: true, callback: function () {
hljs.initHighlightingOnLoad();
} },
{ src: 'reveal/plugin/zoom-js/zoom.js', async: true, condition: function () {
return !!document.body.classList;
} },
{ src: 'reveal/plugin/notes/notes.js', async: true, condition: function () {
return !!document.body.classList;
} }
]
});
</script>
</body>
</html>