Ruby Basic I
Objetives

Intro to programming

Someone else has already had that question


Why Ruby?


What is IRB?

Types & Operators

# This is a Number
25
# This is a Boolean
true
# This is a String
"ruby"
# This is a Nil
nil
Math Operators

# Addition
1 + 2
# Subtraction
1 - 2
# Multiplication
1 * 2
# Division
1 / 2
# Exponent
2 ** 2
# Module
5 % 4 
Printing to the terminal

puts "What's up?"
puts "Bandid@"
puts "==========="
print "What's up? "
print "Bandid@"
String Interpolation

puts "The result is #{1+2}"
Comment your code

# Single-Line Comments
# Hi!
# Multi-Line Comments
=begin
Hi,
How are You?
=end
Introduction to Objects

Everything in Ruby is an Object

Using built-in methods for Numbers & Strings

"I love espresso".length
"Ruby".reverse
"ruby".upcase
"RUBY".downcase
"Ruby".reverse.upcase
5.even?
5.to_s
5.to_r
Defining Variables

number = 1
puts number
# Reusing variable names
number = 4
number = number * 3
puts number + 2
Comparison Operators

# Equals
==
# Not equal
!=
# Greater than
>
# Less than
<
# and
&&
# or
||
# negation
!
Control Flow

# Codeable Applications
age = 18
if age >= 18
puts "Sure you can apply for codable"
else
puts "You still can't bandid@"
end
Loop

# .loop
i = 1
loop do
i += 1
print "#{i}"
if i == 10
break
end
end
# .while
counter = 1
while counter < 11
puts counter
counter = counter + 1
end
# .untill
counter = 1
until counter > 10
puts counter
counter +=1 # operadores de asignación
end
# .for
for num in 1...10
puts num
end

# .each
(1..10).each do |x|
x += 10
puts "#{x}"
end
# .times
5.times { puts "I am learning to code!"}
Questions?

Ruby Basics I
By Paulo Tijero
Ruby Basics I
- 190