Other Pages

Slides

Functions

Functions

For example

Here's a silly function:

def add x, y
  x + y
end

Lab: write a multiply method and use it to multiply 123 * 456

Rant!!!

def rant s
  s.upcase.gsub(" ", "") + "!!!"
end

puts rant "i like pizza"

Lab: use "rant" to rant about something really important!!!

Capitalize Just The First Character

def initial_cap s
  s[0] + s[1,s.length]
end

puts initial_cap("smith")
puts initial_cap("deniro")

Lab: capitalize a few things

Titleize

def titleize string
  string.split(' ').map(&:capitalize).join(' ')
end

LAB: titleize your favorite movies