Other Pages

Expand All
Slides

Functions

Functions

For example

Here's a silly function:

def add x, y
  x + y
end

Rant!!!

def rant s
  s.upcase.gsub(" ", "") + "!!!"
end
puts rant "i like pizza"

Capitalize Just The First Character

def initial_cap s
  s[0] + s[1,s.length]
end
puts initial_cap("McElaney")

Titleize

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

LAB: todo

Back to Learn To Code

If you find something that could be improved, please make a pull request or drop us a note via GitHub Issues (no technical knowledge required).

Source: https://github.com/RailsBridge-CapeTown