-
Notifications
You must be signed in to change notification settings - Fork 22
/
ladies-learning-ruby.html
1806 lines (1644 loc) · 63.4 KB
/
ladies-learning-ruby.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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!--
Google HTML5 slide template
Original slides by:
Authors: Luke Mahé (code)
Marcin Wichary (code and design)
Dominic Mazzoni (browser compatibility)
Charles Chen (ChromeVox support)
URL: http://code.google.com/p/html5slides/
Modifications by: Dessy Daskalov
Modifications by: Carolyn Marshall
-->
<!DOCTYPE html>
<html>
<head>
<title>Ladies Learning Ruby</title>
<meta charset='utf-8'>
<script src='assets/default.js'></script>
</head>
<style>
</style>
<body style='display: none'>
<section class='slides layout-regular template-default'>
<img src='assets/images/ladieslearningcode-125x125.gif'>
<article>
<h1>
Welcome to
<br>
Ladies Learning Code
</h1>
<p>
In partnership with
<img src="assets/images/telus.png" height="191" width="562" alt="Telus logo">
</p>
</article>
<article>
<h1>
Learning to Program
<br>
with Ruby
</h1>
<p>
Content created by Dessy Deskalov
</p>
</article>
<article id="agenda">
<style>
#agenda p { margin: 100px 0px; font-size: 40px; line-height: 50px; };
</style>
<h3>
Agenda
</h3>
<ul class="build">
<li>What is Ruby?</li>
<li>The Anatomy of a Programming Language</li>
<li>Strings, Numbers and Variables</li>
<li>Objects and Methods</li>
<li>Control Flow</li>
<li>Exercises, Puzzles and Challenges</li>
</ul>
</article>
<article id="mentors">
<style>
#mentors p { margin: 100px 0px; font-size: 40px; line-height: 50px; };
</style>
<p>But first...
<h1>
Introductions!
</h1>
</article>
<article id="mentors">
<style>
#mentors p { margin: 100px 0px; font-size: 40px; line-height: 50px; };
</style>
<p>Your instructor today:</p>
<h3>Jenn Cooper</h3>
<br />
<img src="assets/images/programming-yay.gif" style="float:right;" />
<div>
<a href="mailto:[email protected]">[email protected]</a>
<br />
<a href="https://twitter.com/jncoops">@jncoops</a>
<br />
<a href="https://github.com/jenncoop">github.com/jenncoop</a>
</div>
</article>
<article id="workshop-material">
<style>
#workshop-material p { margin: 100px 0px; font-size: 40px; line-height: 50px; };
</style>
<p>Workshop Material:</p>
<a href='https://github.com/jenncoop/LLC-Ruby-Vancouver'>https://github.com/jenncoop/LLC-Ruby-Vancouver</a>
</article>
<article id="before-we-get-started-1">
<style>
#before-we-get-started p { margin: 100px 0px; font-size: 40px; line-height: 50px; };
</style>
<h5>Some things to remember...</h5>
<h3>If the person beside you be like:</h3>
<br />
<img src="assets/images/crazy-programmer.gif" style="float:right;" />
</article>
<article id="before-we-get-started-2">
<style>
#before-we-get-started-2 p { margin: 100px 0px; font-size: 40px; line-height: 50px; };
</style>
<h5>Some things to remember...</h5>
<h3>...And you be like:</h3>
<br />
<img src="assets/images/defeated-programmer.gif" style="float:right;" />
</article>
<article id="before-we-get-started-3">
<style>
#before-we-get-started-3 p { margin: 100px 0px; font-size: 40px; line-height: 50px; };
</style>
<h5>Some things to remember...</h5>
<h3>Don't Worry!</h3>
<br />
<img src="assets/images/cool-programmer.gif" style="float:right;" />
<img src="assets/images/dog.jpg" style="float: left; width: 400px;" />
</article>
<article id="what-is-ruby">
<style>
#what-is-ruby p { margin: 100px 0px; font-size: 40px; line-height: 50px; };
</style>
<h3>
What is Ruby?
</h3>
<p />
<div class="build">
<p class='large-font'>Ruby is a programming language.</p>
<p class='large-font'>Wait ... what's a programming language?</p>
<p class='large-font'>Let's backtrack a bit.</p>
</div>
</article>
<article id='two-things'>
<style>
#two-things p { margin: 200px 0px; }
</style>
<p class='large-font'>There are two things you should know about your computer.</p>
</article>
<article id='computer-wishes'>
<style>
#computer-wishes h3 { padding-bottom: 10px; }
#computer-wishes img { margin-left: 70px; }
</style>
<h3>
1. Your computer speaks a different language.
</h3>
<p>This is how your computer wishes you could speak to it:</p>
<p />
<img src="assets/images/machine-language.jpg" width="600" height="411" border="1">
</article>
<article id='middle-ground'>
<h3>
This is where a programming language comes in.
</h3>
<style>
#middle-ground p { margin-top: 100px }
</style>
<p>A programming language is a language that is relatively <b>easy for you to learn</b>, but can also be <b>understood by the computer</b>.</p>
<p>It's the <b>middle ground</b> between English and the language that the computer understands.</p>
</article>
<article id='stupid-computer'>
<style>
#stupid-computer p { margin: 200px 0px; }
</style>
<h3>
2. Your computer is not very smart.
</h3>
<p class='large-font'>Your computer can only do what you tell it to if you give it exact instructions.</p>
</article>
<article id='stupid-computer'>
<h3>People vs. Computers</h3>
<p class='large-font'>
Suppose you had to teach a person how to make a peanut butter sandwich.
You might give the person an easy to follow recipe.
</p>
</article>
<article>
<h3>People vs. Computers</h3>
<p>1. Toast two slices of bread</p>
<p>2. Spread peanut butter on one slice of bread</p>
<p>3. Spread jam on the other slice of bread</p>
<p>4. Put the two pieces of bread together</p>
<p>5. Put the sandwich on a plate and serve it</p>
</article>
<article>
<h3>People understand GENERAL instructions.</h3>
<p>
We left out some parts of the process, but a person could figure out:
</p>
<p>Where to find the ingredients</p>
<p>To use a butter knife to spread the peanut butter</p>
<p>To put the bread in a toaster in order to toast it</p>
<p>etc, etc, etc (there are many little steps)</p>
</article>
<article id='computers-exact'>
<style>
#computers-exact p { margin: 150px 0px; };
</style>
<h3>Computers understand EXACT instructions.</h3>
<p class='large-font'>
This same recipe for a computer would be much, much longer.
</p>
</article>
<article>
<h3>1. Toast two slices of bread</h3>
<p>What is bread?</p>
<p>Where is it found?</p>
<p>How do I open the bag?</p>
<p>What is a slice?</p>
<p>How do I slice the bread?</p>
<p>How do I "toast"?</p>
<p>What is a toaster?</p>
<p>How do I use a toaster?</p>
<p>etc, etc, etc</p>
</article>
<article>
<h3>2. Spread peanut butter on one slice of bread</h3>
<p>What is peanut butter?</p>
<p>How do I "spread" peanut butter?</p>
<p>What is a butter knife?</p>
<p>Where is it found?</p>
<p>How do I open the knife drawer?</p>
<p>Which slice do I spread it on?</p>
<p>How much peanut butter do I spread?</p>
<p>etc, etc, etc</p>
</article>
<article id='programming-languages'>
<style>
#programming-languages p { margin-top: 80px; }
#programming-languages .mixed-font { line-height: 50px; }
#programming-languages b { font-size: 40px; }
</style>
<h3>Back to programming languages.</h3>
<p>A programming language makes it easier for you to give the computer instructions.</p>
<p class='mixed-font'>
It's made up of <b>simple elements</b>, that when <b>combined together</b>,
are used to write a set of <b>instructions</b> that the computer then breaks down and interprets as its own language.
</p>
</article>
<article id='learned-programming'>
<style>
#learned-programming p { margin-top: 100px; }
</style>
<h3>
You've just learned what programming is!
</h3>
<p class='large-font'>Programming is writing out <b>exact instructions</b> that your computer can follow to do things.</p>
</article>
<article id='ruby-rocks'>
<style>
#ruby-rocks .large-font { margin: 50px; }
</style>
<h3>
Why Ruby Rocks!
</h3>
<p>Created in 1993 by Yukihiro Matsumoto, from Japan.</p>
<p class='large-font'>
"I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy.
That is the primary purpose of the Ruby language."
</p>
<p>Ruby is <b>fun</b>, it's <b>easy to learn</b>, and the <b>syntax is very forgiving</b>.</p>
</article>
<article>
<p class='large-font'>This is some code in Java:</p>
<section>
<pre>
class Person {
private String name, int age;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public String getAge() {
return age;
}
}</pre>
</section>
</article>
<article>
<p class='large-font'>The equivalent code in Ruby looks like this:</p>
<section>
<pre>
class Person
attr_accessor :name, :age
end
</pre>
</section>
</article>
<article id='ruby-robot'>
<style>
#ruby-robot img { margin: 50px 0 0 450px; }
</style>
<h3>
Meet Ruby
</h3>
<p>Ruby is an interpreter.</p>
<p>Ruby understands the Ruby language and translates it into computer language.</p>
<p>We can give Ruby instructions with files or with IRB (Interactive Ruby).</p>
<img style="width: 30%; position: absolute; bottom: 20px; right: 20px" src="assets/images/ruby-logo.png" />
</article>
<article id='irb-intro'>
<style>
#irb-intro .instructions { margin-top: 100px; }
</style>
<h3>
Time to see Ruby in action!
</h3>
<p>IRB is like text messaging with Ruby.</p>
<p>You'll ask Ruby to do something, and she will respond.</p>
<div class='instructions'>
<p><b>OS X</b></p>
<section>
<pre>Applications -> Utilities -> Terminal</pre>
</section>
<p />
<p><b>Windows</b> (C:\windows\system32\cmd.exe)</p>
<section>
<pre>Start -> All Programs -> Accessories -> Command Prompt</pre>
</section>
</div>
</article>
<article id='ask-ruby'>
<style>
#ask-ruby .large-font { margin-top: 100px; }
</style>
<section class='build'>
<pre>irb</pre>
<pre>irb(main):001:0> </pre>
<p class='large-font'>Let's ask Ruby to do something.</p>
</section>
</article>
<article>
<p class='large-font'>Ruby can do math, and she can do it much quicker than a person can.</p>
<section class='build'>
<pre>> 1 + 1<br/>=> 2</pre>
<pre>> 462 * 86<br/>=> 39732</pre>
</section>
</article>
<article id='ruby-knows'>
<section class='build'>
<p class='large-font'>Ruby knows the difference between a number and a word...</p>
<pre>> 1 + 2 + 3<br>=> 6</pre>
<pre>> "ladies" + "learning" + "code"<br/>=> "ladieslearningcode"</pre>
<p class='large-font'>...and can perform operations on them, too!</p>
<pre>> "ladies learning code".reverse<br/>=> "edoc gninrael seidal"</pre>
<pre>> "ladies learning code".upcase<br/>=> "LADIES LEARNING CODE"</pre>
</section>
</article>
<article>
<h3>
Variables
</h3>
<section style="margin-top:10px" class='build'>
<p>What if we don't want to type "ladies learning code" each time we want to use it?</p>
<p>We can use variables to store things for later use.</p>
<pre>> llc = "ladieslearningcode"<br/>=> "ladieslearningcode"</pre>
<p>You've just <b>assigned</b> the String "ladieslearningcode" to the <b>variable</b> llc.</p>
<p>A programmer would say that the variable llc points to the object "ladieslearningcode".</p>
</section>
</article>
<article id='back-ruby-robot'>
<style>
#back-ruby-robot p { margin: 80px 0 50px 0; }
</style>
<h3>
Variables in Ruby Language
</h3>
<p>You told Ruby the <i>variable</i> <b>llc</b> points to the <i>string</i> "<b>ladieslearningcode</b>".</p>
<p>Ruby files "<b>ladieslearningcode</b>" away under <b>llc</b>.</p>
<p>Next time you want the <i>string</i> "<b>ladieslearningcode</b>", you just tell Ruby to use the <i>value</i> of <b>llc</b>.</p>
</article>
<article>
<h3>
Variables Can (And Often Do!) Vary
</h3>
<p>A variable is called just that because the object it points to can change.</p>
<section class='build'>
<pre>> llc = "a lady learning code"<br/>=> "a lady learning code"</pre>
<div>llc <img src='assets/images/arrow.png'> "a lady learning code"</div>
<p>Now let's ask for the value of llc.</p>
<pre>> llc<br/>=> "a lady learning code"</pre>
</section>
</article>
<article>
<p>Let's try some more</p>
<section class='build'>
<pre>> llc = 99<br/>=> 99</pre>
<div>llc <img src='assets/images/arrow.png'> 99</div>
<p>Let's ask for the value of llc once again.</p>
<pre>> llc<br/>=> 99</pre>
</section>
</article>
<article>
<h3>The More the Merrier</h3>
<p>Let's introduce another variable.</p>
<section class='build'>
<pre>> copy_cat = llc<br/>=> 99</pre>
<div>llc <img src='assets/images/arrow.png'> 99 <img src='assets/images/back-arrow.png'> copy_cat</div>
</section>
</article>
<article>
<p>Let's ask for the value of each variable.</p>
<section class='build'>
<pre>> llc<br/>=> 99</pre>
<pre>> copy_cat<br/>=> 99</pre>
<p>Now set llc back to "ladieslearningcode"</p>
<pre>> llc = "ladieslearningcode"<br/>=> "ladieslearningcode"</pre>
</section>
</article>
<article id='integer-string'>
<style>
#integer-string .ruby-class { margin: 100px 0px; }
</style>
<h3>
Integers and Strings
</h3>
<p class='ruby-class'>Numbers without decimals are called <b>INTEGERS</b>. We just did some math with some integers.</p>
<p class='ruby-class'>Letters, words, and sentences are called <b>STRINGS</b>. We tell Ruby that we are intending to use a string by wrapping it in quotes.</p>
</article>
<article id='objects-objects'>
<style>
#objects-objects .large-font { margin: 70px 0px; }
#objects-objects .med-font { margin: 10px;}
</style>
<h3>
Objects, Objects, Everywhere!
</h3>
<section class='build'>
<p class='large-font'>Everything in Ruby is an Object.</p>
<b>Great, but what is an object?</b>
<p class='large-font'>An OBJECT is an INSTANCE of a CLASS.</p>
<b>A what is a what of a what?</b>
</section>
</article>
<article id='classes-galore'>
<style>
#classes-galore .build { margin-top: 40px; }
#classes-galore .large-font { margin: 50px 0px; }
</style>
<h3>Classes</h3>
<div class='build'>
<p>Before she can do something with an object, Ruby needs to know what kind of object she's dealing with.</p>
<p><b>Why?</b></p>
<p>Toasting bread is not the same as toasting a marshmallow.</p>
<p><b>So how do classes help?</b></p>
<p>Classes define objects and what can be done with them.</p>
<p>The <b>bread class</b> will have different instructions for "toast" than the <b>marshmallow class</b>.</p>
<p class="large-font">Objects have an <b>IS A</b> relationship with their classes.</b></p>
<br/>
</div>
</article>
<article id='classes-galore-2'>
<style>
#classes-galore-2 .build { margin-top: 40px; }
#classes-galore-2 .large-font { margin: 70px 0px; }
</style>
<h3>Classes so far</h3>
<div class='build'>
<p>We have already looked at 2 classes in Ruby: <b>Integer</b> and <b>String</b></p>
<p>The number <b>1</b> IS AN <b>Integer</b>.</p>
<p>The word <b>"ladies"</b> IS A <b>String</b>.</p>
<p>1 and "ladies" are <b>Objects</b>.</p>
</div>
</article>
<article id='classes-galore-2'>
<style>
#classes-galore-2 .build { margin-top: 40px; }
#classes-galore-2 .large-font { margin: 70px 0px; }
</style>
<h3>Let's try some more!</h3>
<p>Hint: Remember, an <b>Object</b> <u>IS A</u> instance of a <b>Class</b>!</p>
<table>
<tr style="border-bottom: 1px solid black"><td style="border-right: 1px solid black">Object</td><td>Class</td></tr>
<tr class='build'><td style="border-right: 1px solid black">3</td><td>Integer</td></tr>
<tr class='build'><td style="border-right: 1px solid black">"3"</td><td>String</td></tr>
<tr class='build'><td style="border-right: 1px solid black">London</td><td>City</td></tr>
<tr class='build'><td style="border-right: 1px solid black">Jack of Spades</td><td>Playing Card</td></tr>
<tr class='build'><td style="border-right: 1px solid black">Donald Duck</td><td>Duck</td></tr>
<tr class='build'><td style="border-right: 1px solid black">Daisy Duck</td><td>Duck</td></tr>
<tr class='build'><td style="border-right: 1px solid black">The Hobbit</td><td>Book/Movie</td></tr>
</table>
</article>
<article id='back-ruby-robot'>
<style>
#back-ruby-robot p { margin: 40px 0 30px 0; }
</style>
<h3>
Classes and Ruby
</h3>
<p>Ruby uses what she knows about an object to perform actions on it.<p>
<p>When you give Ruby a set of instructions, she asks the following:
<ul style="list-style-type:circle">
<li>What am I supposed to do with this object?</li>
<li>Do I know how to do that action on it?</li>
</ul>
</p>
<p>If she knows how to perform the action on the object, she does it. If she doesn't, you'll get an error.</p>
</article>
<article id='ruby-method'>
<style>
#ruby-method p { margin: 60px 0px; }
</style>
<h3>
Methods
</h3>
<div class='build'>
<p>The <b>actions</b> you can perform on an <b>object</b> are called <b>methods</b>.</p>
<p>Every <b>object</b> that IS A <b>class</b> can perform the methods defined by that class.</p>
</article>
<article id='integer-methods'>
<style>
#integer-methods p { margin: 60px 0px; }
</style>
<h3>
Integer Methods
</h3>
<div class='build'>
<p>The <b>Integer class</b> has instructions for the methods <b>next</b>, <b>odd?</b>, and <b>even?</b>.</p>
<p>You can call <b>next</b>, <b>odd?</b>, and <b>even?</b> on ALL Objects that are <b>Integers</b></b>
</div>
</article>
<article id='string-methods'>
<style>
#string-methods p { margin: 60px 0px; }
</style>
<h3>
String Methods
</h3>
<div class='build'>
<p>The <b>String class</b> has instructions for the methods <b>capitalize</b>, <b>upcase</b>, and <b>reverse</b>.</p>
<p>You can call <b>capitalize</b>, <b>upcase</b>, and <b>reverse</b> on ALL Objects that are <b>Strings</b>.</p>
</div>
</article>
<article id='back-ruby-robot'>
<style>
#back-ruby-robot .large-font { margin: 80px 0 50px 0; }
</style>
<h3>
Classes and Ruby
</h3>
<p>Let's walk through some examples from Ruby's perspective</p>
<pre>>counter = 0<br/>>counter.next</pre>
<table>
<tr class='build'><td>What am I supposed to do with this object?</td><td>next</td></tr>
<tr class='build'><td>Do I know how to do that action with this object?</td>
<td>Yes! The <b>Integer</b> class defines a method <b>next</b> and returns the next number.</td></tr>
</table>
<div class='build'>
<pre>=>1</pre>
</div>
</article>
<article>
<h3>
Playing with Integers
</h3>
<section class='build'>
<pre>> 99.zero?<br/>=> false</pre>
<pre>> 99.odd?<br/>=> true</pre>
<pre>> 99.even?<br/>=> false</pre>
</section>
</article>
<article>
<h3>
Another example
</h3>
<pre>>title = "Peter Rabbit"<br/>>title.reverse</pre>
<table>
<tr class='build'><td>What am I supposed to do with this object?</td><td>reverse</td></tr>
<tr class='build'><td>Do I know how to do that action on this object?</td>
<td>Yes! The <b>String</b> class defines a method <b>reverse</b> and returns the string in reverse order.</td></tr>
</table>
<div class='build'>
<pre>=>"tibbaR reteP"</pre>
</div>
</article>
<article>
<h3>
Fun with strings
</h3>
<section class='build'>
<pre>> "ladieslearningcode".capitalize<br/>=> "Ladieslearningcode"</pre>
<pre>> "ladieslearningcode".upcase<br/>=> "LADIESLEARNINGCODE"</pre>
<pre>> "LADIESLEARNINGCODE".downcase<br/>=> "ladieslearningcode"</pre>
<pre>> "ladieslearningcode".reverse<br/>=> "edocgninraelseidal"</pre>
</section>
</article>
<article>
<h3>
Method Errors
</h3>
<pre>>myNumber = 123<br/>>myNumber.reverse</pre>
<table>
<tr class='build'><td>What am I supposed to do with this object?</td><td>reverse</td></tr>
<tr class='build'><td>Do I know how to do that action on this object?</td>
<td>No. The <b>Integer</b> class does not define a method <b>reverse</b>.</td></tr>
</table>
<div class='build'>
<pre>=>NoMethodError: undefined method `reverse' for 123:Fixnum
from (irb):1
from :0
</pre>
</article>
<article id='class-methods-objects'>
<style>
#class-methods-objects p { margin: 36px 0px;}
</style>
<h3>
Methods and Objects and Classes, Oh My!
</h3>
<p>How can I find the class of my object?</p>
<pre>> mysteryObject = "What am I?"<br/>> mysteryObject.class<br/>=> String</pre>
<p>How do I know what methods I can call on my object?</p>
<pre>> mysteryObject.methods<br/>=> ["upcase!", "zip", "pretty_print_cycle"....]</pre>
<p>How do I know what those methods do?</p>
<a href="http://ruby-doc.org/">http://ruby-doc.org/</a>
</article>
<article id='built-in-methods'>
<style>
#built-in-methods p { margin: 80px 0px; }
</style>
<h3>
Built-in Classes
</h3>
<section class='build'>
<p>Ruby comes with many built-in classes that we can use.</p>
<p>String, Integer, File, Hash, Array...</p>
<p>You can read about all the built-in objects <a href="http://www.ruby-doc.org/core-2.1.1/">here</a></p></section>
</article>
<article id='custom-classes'>
<style>
#class-methods .large-font { margin: 200px 0px; }
</style>
<h3>
Custom Classes</h3>
<p>What about City and Playing Card and Duck?</p>
<p>We won't do it today, but you can make your own classes and objects! Here's a teaser for you to start exploring on your own</p>
<pre>class Duck
attr_accessor :name
def quack
puts "Quack, quack!"
end
end</pre>
<pre>> donald = Duck.new<br/> donald.name = "Donald Fauntleroy Duck"<br/> donald.quack<br/>=> "Quack, quack!"</pre>
</pre>
</article>
<article>
<h3>Variables and methods</h3>
<section class='build'>
<pre>> llc = "ladieslearningcode"</pre>
<pre>> llc.reverse<br/>=> "edocgninraelseidal"</pre>
<p>Try asking for the value of llc now.</p>
<pre>> llc<br/>=> "ladieslearningcode"</pre>
</section>
</article>
<article id='wait-why'>
<style>
#wait-why p { margin: 50px 0px; }
</style>
<h3>Wait. Why didn't it change?</h3>
<section class='build'>
<p class='large-font'>llc is still pointing to "ladieslearningcode". You didn't tell it to point to a different string.</p>
<div>llc <img src='assets/images/arrow.png'> "ladieslearningcode"</div>
<p class='large-font'>If you want the value to change, you have to set it to something else.</p>
</section>
</article>
<article>
<section class='build'>
<pre>> llc = llc.reverse<br/>=> "edocgninraelseidal"</pre>
<pre>> llc<br/>=> "edocgninraelseidal"</pre>
<p class='large-font'>If you want the value of a variable to change, you have to explicitly tell it to change.</p>
</section>
</article>
<article>
<h3>
Let's Try One More
</h3>
<div class='build'>
<pre>> llc.length</pre>
<pre>=> 18</pre>
<p class='large-font'>
You're probably starting to get a sense of how Twitter knows
how many characters you've typed in.
</p>
</div>
</article>
<!-- Twitter stuff -->
<article>
<h3>Doing like Twitter does.</h3>
<section class='build'>
<pre>> tweet = "I'm writing my first program at the @learningcode<br>Intro to Ruby workshop!"</pre>
<pre>=> "I'm writing my first program at the @learningcode <br>Intro to Ruby workshop!"</pre>
<pre>> tweet.length</pre>
<pre>=> 73</pre>
<p class='large-font'>We now know enough to write a program.</p>
</section>
</article>
<article>
<h3>
Writing Our First Program
</h3>
<p>
Open any text editor, add the same code, and save it as twitter.rb in your llc directory.
</p>
<section>
<pre>tweet = "I'm writing my first program at the @learningcode<br>Intro to Ruby workshop!"<br>tweet.length</pre>
</section>
<p>To run your program, type <b>quit</b> to exit from IRB, and then type:</p>
<section>
<pre>ruby twitter.rb</pre>
</section>
<div class='build'><p>Wait, what? Why didn't it show me the length of my string?</p></div>
</article>
<article id='ruby-output'>
<style>
#ruby-output .large-font { margin: 50px 0px; }
</style>
<h3>
Outputting Text to the Screen
</h3>
<p class='large-font'>IRB is like back-and-forth text messaging.</p>
<p class='large-font'>A program has to be told when to output something</p>
<p>Modify your program:</p>
<section>
<pre>tweet = "I'm writing my first program at the @learningcode<br>Intro to Ruby workshop!"<br>puts tweet.length</pre>
</section>
</article>
<!-- just words, highlight in a different colour before -->
<article id='recap-one'>
<style>
#recap-one .large-font { margin: 40px 0px; text-align: center; }
</style>
<h3>
Recap Slide
</h3>
<div class='build'>
<p class='large-font'>Integer</p>
<p class='large-font'>String</p>
<p class='large-font'>Class</p>
<p class='large-font'>Object</p>
<p class='large-font'>Method</p>
<p class='large-font'>Variable</p>
</div>
</article>
<article id='puzzle-one'>
<style>
#puzzle-one .large-font { margin: 100px 0px; }
</style>
<h3>
Puzzle One - Variables
</h3>
<p class='large-font'>Open puzzle_1.rb in the puzzles folder, and write down the output you expect to see if you were to run this script.</p>
<p class='large-font'>If you're not sure of something, remember that you can type <b>irb</b> again and try it out.</p>
</article>
<article id='real-twitter'>
<style>
#real-twitter .large-font { margin: 60px 0px; }
</style>
<h3>
Getting Input From the User
</h3>
<p>The real Twitter...</p>
<div class='build'>
<p class='large-font'>Asks you to type something.</p>
<p class='large-font'>Tells you how many characters you're working with.</p>
<p>So far, we've just been putting our tweet directly into the program.</p>
</div>
</article>
<article>
<h3>
Asking for Input
</h3>
<p>The <b>puts</b> method is used for output, and the <b>gets</b> method is used for input. Try this:</p>
<p>The gets method warns Ruby that you're about to speak.</p>
<section class='build'>
<pre>> tweet = gets</pre>
<pre class='all-string'>I'm learning Ruby with #ladieslearningcode</pre><pre>=> "I'm learning Ruby with #ladieslearningcode\n"</pre>
<p>
Wait, we didn't type \n in our tweet. What is that?
</p>
</section>
</article>
<article>
<h3>
Asking for Input
</h3>
<p>
The \n is there because you hit the enter button after you typed your tweet. It represents a new line, and counts as exactly one character.
To get rid of it, do this:
</p>
<section class='build'>
<pre>> tweet = gets.chomp</pre>
<pre class='all-string'>I'm learning Ruby with #ladieslearningcode</pre>
<pre>=> "I'm learning Ruby with #ladieslearningcode"</pre>
</section>
</article>
<article>
<h3>
Asking for Input
</h3>
<p>Now try this:</p>
<section class='build'>
<pre>> tweet = gets.chomp</pre>
<pre class='all-string'>I'm a lady learning code with @learningcode #ladieslearningcode</pre>
<pre>=> "I'm a lady learning code with @learningcode #ladieslearningcode"</pre>
<pre>> puts tweet</pre>
<pre class='all-string'>I'm a lady learning code with @learningcode #ladieslearningcode<br>=> nil</pre>
</section>
</article>
<article id='nil-nothing'>
<style>
#nil-nothing p { margin: 80px 0px; }
</style>
<h3>What's nil? It's nothing, don't worry.</h3>
<p>You asked Ruby to output your tweet, and Ruby did just that.</p>
<p>
Remember that in IRB, Ruby always responds to your message.
This time, it gave the output, and had nothing else to say, so it returned nil.
</p>
<p>nil is also an Object, and it just represents nothing.</p>
</article>
<article id='ask-for-tweet'>
<style>
#ask-for-tweet .build { margin-top: 60px; }
</style>
<h3>
Back to your Twitter Program
</h3>
<p>Working with your group, modify your Twitter program to do the following:</p>
<div class='build'>
<p>1. Ask (politely!) for a tweet from the user.</p>
<p>2. Store the tweet in a variable, without \n</p>
<p>3. Output the tweet the user gave.</p>
<p>4. Output the number of characters in the tweet.</p>
<p>5. Output how many <b>more</b> characters the user can add until they hit 140 characters.</p>
<p>(answers in assignments/twitter_3.rb)</p>
</div>
</article>
<article id='conditional-twitter-1'>
<style>
#conditional-twitter-1 .large-font { margin-top: 100px; }
</style>
<h3>
Giving Output Based on Input
</h3>
<p>Twitter...</p>
<p class='large-font'>Lets you send your tweet if it is 140 characters or less</p>
<p class='large-font'>Tells you that your tweet is too long to send otherwise.</p>
</article>
<article id='conditional-twitter-2'>
<style>
#conditional-twitter-2 .large-font { margin-top: 100px; }
</style>
<h3>Giving Output Based on Input</h3>
<p class='large-font'>
So far we know how to determine the length of the user's tweet.
</p>
<p class='large-font'>
We don't know how to tell them
whether they can or cannot send their tweet, depending on it's length.
</p>
</article>
<article id='conditional-logic'>
<style>
#conditional-logic .large-font { margin-top: 100px; }
</style>
<h3>Conditional Logic</h3>
<p class='large-font'>Programming is writing out sets of simple instructions for the computer to follow.</p>
<p class='large-font'>Let's break down out tweet logic into simple instructions.</p>
</article>
<article id='conditional-instructions'>
<style>
#conditional-instructions .large-font { margin-top: 80px; }
</style>
<h3>
Conditional Logic
</h3>
<p>We want our program to ...</p>
<p class='large-font'>if the tweet is greater than 140 characters, tell the user that they cannot send their tweet</p>
<p class='large-font'>if the tweet is less than or equal to 140 characters, tell the user that they can send their tweet</p>
</article>
<article id='greater-than'>
<style>
#greater-than .large-font { margin: 100px 0px; }
</style>
<h3>
Conditional Logic: Greater Than
</h3>
<p class='large-font'>The math symbol for <b>greater than</b> is <b>></b></p>
<p>Try the code below in IRB:</p>
<section class='build'>
<pre>> 200 > 140</pre><pre>=> true</pre>
</section>
</article>
<article>
<h3>
Conditional Logic: Greater Than
</h3>
<p>Now try:</p>
<section class='build'>
<pre>> number_of_characters = 200</pre><pre>=> 200</pre>
<pre>> number_of_characters > 140</pre><pre>=> true</pre>
</section>
</article>