** = expoonent
% = modulo
puts - includes (or newline as they call it).
print - no newline generated after string
"some string".length
.length
.reverse
.upcase
.downcase
.capitalize!
if string.include? "s"
.gsub!(/s/, "th")
puts "paul".upcase

COMMENTS

# siingle line comment
=begin
Multiple line
comment
=end
name = "Paul".downcase.reverse.upcase => "LUAP"
gets.chomp => get input and remove CR
print "What's your first name? "
first_name = gets.chomp.capitalize!
print "What's your last name? "
last_name = gets.chomp.capitalize!
print "What's your city? "
city_name = gets.chomp.capitalize!
print "What's your state? "
state_name = gets.chomp.upcase!
puts "#{first_name} #{last_name} from #{city_name} in #{state_name}"
CONTROL FLOW
if
elsif
else
end
unless
==, !=, , =, &&, ||, !
EXAMPLE
print "Thtring, pleathe!: "
user_input = gets.chomp
user_input.downcase!
if user_input.include? "s"
user_input.gsub!(/s/, "th")
else
puts "Nothing to do here!"
end
puts "Your string is: #{user_input}"

LOOPS

counter = 1
while counter < 11
puts counter
counter = counter + 1
end
for num in 1...10 OR for num in 1..10 # note the use of two or 3 dots give different results
puts num
end
Infinite loop => loop { print "~Hello World" }
i = 0
loop do
i += 1
print "#{i}"
break if i > 5
end
for i in 1..5 # skips even numbers
next if i % 2 == 0
print i
end

OPERATORS

+=, -=, *=, /=

Arrays

my_array = [1,2,3,4,5]
muluti_array = [[1,2,3],[1,2,3],[1,2,3]]
multiarray.each -- will access each array in the array.
my_array.each do |x|
:
end
my_array.each { |item| print item * 2}

Hashes

key value pairs.
my_hash = { "name" => "Eric", "age" => 26, "hungry?" => true }
puts my_hash["name"]
puts my_hash["age"]
puts my_hash["hungry?"]
my_hash = Hash.new
pets = Hash.new
pets["Rio"] = "Moluccan Cockatoo"
family = { "Homer" => "dad", "Marge" => "mom", "Lisa" => "sister", "Maggie" => "sister", "Abe" => "grandpa", "Santa's Little Helper" => "dog" }
pets.each { |x| puts "#{x}" }
family.each { |x, y| puts "#{x}: #{y}" }

Times Split

10.times { print "This will print ten times "}
words = sometext.split(" ")
words.each do |astring |

SORTS

puts "Text please: "
text = gets.chomp
words = text.split(" ")
frequencies = Hash.new(0)
words.each { |word| frequencies[word] += 1 }
frequencies = frequencies.sort_by {|a, b| b }
frequencies.reverse!
frequencies.each { |word, frequency| puts word + " " + frequency.to_s }
my_array.sort!
COMBINED
a  b, -1, 0, +1
# To sort our books in ascending order, in-place books.sort! { |firstBook, secondBook| firstBook  secondBook } # Sort your books in descending order, in-place below books.sort! { |firstBook, secondBook| secondBook  firstBook }

METHODS

def puts_1_to_10
  (1..10).each { |i| puts i }
end

puts_1_to_10 # Ignore this for now. We'll explain it soon!

BLOCKS

1.times do puts "I'm a code block!" end 1.times { puts "As am I!" }

# block that capitalizes each string in the array ["ryan", "jane"].each {|string| puts "#{string[0].upcase}#{string[1..-1]}"} # prints "Ryan", then "Jane"