Ruby is...

A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.

RVM first

Visit https://rvm.io for more details.

.rvmrc file

.ruby-version file

.ruby-gemset file

RVM Best Practices

Run Ruby files

hello_world.rb hello_world.rb

Interactive Ruby

Everything is an object

Numbers

Numbers conversion

Arithmetic operators

Assume variable a holds 10 and variable b holds 20 then:

OperatorDescriptionExample
+Addition - Adds values on either side of the operator a + b will give 30
-Subtraction - Subtracts right hand operand from left hand operand a - b will give -10
*Multiplication - Multiplies values on either side of the operator a * b will give 200
/Division - Divides left hand operand by right hand operand b / a will give 2
%Modulus - Divides left hand operand by right hand operand and returns remainder b % a will give 0
**Exponent - Performs exponential (power) calculation on operators a**b will give 10 to the power 20

Assignment Operators

Assume variable a holds 10 and variable b holds 20 then:

OperatorDescriptionExample
=Simple assignment operator, Assigns values from right side operands to left side operand c = a + b will assigne value of a + b into c
+=Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a
-=Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a
*=Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a
/=Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / a
%=Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a
**=Exponent AND assignment operator, Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a

String

Interpolation

String

Concatenation

String

Accessing

String

Useful methods

Follow by http://ruby-doc.org/core-2.0/String.html for more information

Array

Follow by http://ruby-doc.org/core-2.0/Array.html for more information

Creating

Array

Accessing elements

Array

Adding items

Array

Removing items

Array

Obtaining information

Array

Concatenation

Array

Operations

Array

Iterators

each each_index each_with_index

Symbol

Follow by http://www.ruby-doc.org/core-2.0.0/Symbol.html for more information.

Hash

Follow by http://www.ruby-doc.org/core-2.0.0/Hash.html for more information.

Creating

Hash

Default value

Hash

Removing items

delete delete_if keep_if shift

Hash

Useful methods

each each_key each_value

Hash

Useful methods

key? value? keys values values_at

Hash

Useful methods

length merge select

Range

Follow by http://www.ruby-doc.org/core-2.0.0/Range.html for more information.

Time

Follow by http://www.ruby-doc.org/core-2.0.0/Time.html for more information.

File

Follow by http://www.ruby-doc.org/core-2.0.0/File.html for more information.

new open, close

File

Read

read gets readlines each

File

Write

write, puts

File

delete rename ftype join expand_path

Dir

Follow by http://ruby-doc.org/core-2.0/Dir.html for more information.

entries glob foreach mkdir

Variables

Local

Instance

Global

Constant

If, unless

If, else

Short-if expression

Or, and

Case, when

Loop

While

Like do...while

Until

For

Each

Times

Upto

Methods

Methods

Definition

Methods

Arguments

Methods

Return values

Methods

Blocks

Methods

Closures

Methods

Convert the block to a Proc

Methods

Proc aka procedure

Methods

Anonymous

Proc vs lambda

Lambdas check the number of arguments

Proc vs lambda

Lambdas have lesser returns

Proc vs lambda

Conclusion

Method to object

Methods

Naming

? - return true or false

! - change the current object

Operators

Ruby Koans

Ruby Koans Online

The Ruby Koans are a great way to learn about the Ruby language.

/

#