Download - Introduction to ruby
![Page 1: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/1.jpg)
Introduction to Ruby
Andrew Liu
![Page 2: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/2.jpg)
Ruby is…
• Designed by Yukihiro Matsumoto (松本行弘)
– "I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language“
• An object-oriented scripting language
• Easy to learn!
![Page 3: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/3.jpg)
Philosophy
• Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something."
• They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves.
![Page 4: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/4.jpg)
![Page 5: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/5.jpg)
Naming Convention
• CamelCase
– Class names, module names
• ALLCAPITAL
– Constants
• words_with_underscore
– Method names, variable names
• $ prefix
– Global variables
![Page 6: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/6.jpg)
Everything is an object!
![Page 7: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/7.jpg)
Strings
![Page 8: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/8.jpg)
String Methods
![Page 9: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/9.jpg)
Array
![Page 10: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/10.jpg)
What if I want to reverse the array?
http://ruby-doc.org/core/
![Page 11: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/11.jpg)
![Page 12: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/12.jpg)
Range
![Page 13: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/13.jpg)
Hash
![Page 14: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/14.jpg)
Block
![Page 15: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/15.jpg)
How does it work?
![Page 16: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/16.jpg)
More About Class
![Page 17: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/17.jpg)
More About Class
![Page 18: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/18.jpg)
Class
• Variable
– @@ prefix: Shared by all class instances
– @ prefix: Contains instances information
– No prefix: normal variables
• Methods
– self. Prefix: Class methods, as known as static method
– No prefix: Instance methods, must be called with a instance
![Page 19: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/19.jpg)
Creating Instance
![Page 20: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/20.jpg)
![Page 21: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/21.jpg)
Flow Control
![Page 22: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/22.jpg)
Cases
![Page 23: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/23.jpg)
While
![Page 24: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/24.jpg)
For
![Page 25: Introduction to ruby](https://reader034.vdocument.in/reader034/viewer/2022052505/5555a76ed8b42afe5d8b458a/html5/thumbnails/25.jpg)
Resources
• Programming Ruby (Bible)
– http://www.ruby-doc.org/docs/ProgrammingRuby/
• Ruby API Document
– http://ruby-doc.org/core/
• TryRuby
– http://tryruby.org/
• Ruby Warrior
– https://github.com/ryanb/ruby-warrior