Introduction to Ruby

What is Ruby

  • Interpreted/high level language
  • Dynamic 
  • Build for programmer productivity

Why do we program?

Computation

We program because of limitations in terms of brain power.

What is programming?

You have done it for a week now

A klutzy definition of programming

Programming is data and operations on data   

The slides end here

Let's code :)

But just before we do that

Let's get to know our objectives first 

  1. Understand what a programming language is
  2. Solve one problem
  3. Solve two problems
  4. Solve more problems
  5. Solve even more problems
  6. Solve all the problems in the world -- IMPOSSIBLE!

Objectives

Since data varies its important to categorize data into types

 

Data types

  1. Numbers --> Calculations
  2. Strings --> Information 

Data types

Data types

1 + 1

--> 2

"String"

--> String

A symbol or name for referencing a stored value. 

Variables

ego = "I am the best ruby programmer in the world"

hater = "Shut up you ego centric maniac"


That behaviour is referred to as a method.

Data has behaviour

"String".reverse
--> gnirtS

puts "Hello world!"

--> Hello World!

In ruby if you want to see all behaviours of a data type, use .methods method

 

Formats for organizing and storing data in a way so that it can be used efficiently

 

Data Structures

Text

Arrays

miami = [ 'Wade', 'Bosh', 'Haslem', 'Cole', 'Chalmers']

heat = ['Dwayne', 'Chris', 'Udonis', 'Norris', 'Mario']

Use arrays when the order of data matters

Text

Hashes

miami = {'Wade' => 'Dwayne', 'Chris => 'Bosh', 'Haslem' => 'Udonis'}

Use hashes for key, value situations.

Take 5

No more slides after this :)

Intro to Ruby

By Alvin Kato

Intro to Ruby

Basic intro to ruby and programming

  • 191