Slide 1

Slide 1 text

Introduction to Ruby Andrew Liu

Slide 2

Slide 2 text

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!

Slide 3

Slide 3 text

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.

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Naming Convention • CamelCase – Class names, module names • ALLCAPITAL – Constants • words_with_underscore – Method names, variable names • $ prefix – Global variables

Slide 6

Slide 6 text

Everything is an object!

Slide 7

Slide 7 text

Strings

Slide 8

Slide 8 text

String Methods

Slide 9

Slide 9 text

Array

Slide 10

Slide 10 text

What if I want to reverse the array? http://ruby-doc.org/core/

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Range

Slide 13

Slide 13 text

Hash

Slide 14

Slide 14 text

Block

Slide 15

Slide 15 text

How does it work?

Slide 16

Slide 16 text

More About Class

Slide 17

Slide 17 text

More About Class

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Creating Instance

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Flow Control

Slide 22

Slide 22 text

Cases

Slide 23

Slide 23 text

While

Slide 24

Slide 24 text

For

Slide 25

Slide 25 text

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