This site is a preview of the curriculum for our Summer 2018 bootcamp in Burlington, Vermont. As we continue our preparation, courses and lessons will appear and disappear; we will rename, rearrange, clarify, and obfuscate as needed... Please consider this a work in progress and keep checking in.
Learn to Code with Ruby:
- just like a VARIABLE is a name for a chunk of data
- a FUNCTION is a name for a chunk of code
- if you have some code you want to run again and again
- or just run once, but keep it organized
Here's a not very useful function:
def add x, y x + y end
defmeans "define a function"
addis the name of the function
x, yare the parameters of the function
x + yis the body of the function
- also the return value
Call Me, Maybe
You call a function by its name
def add x, y x + y end add 2, 3 # returns 5 add 12, 30 # returns 42
def rant s s.upcase.gsub(" ", "") + "!!!" end puts rant "i like pizza"
Capitalize Just The First Character
def initial_cap s s + s[1,s.length].downcase end puts initial_cap("McElaney")
this program prints
def titleize string string.split(' ').map(&:capitalize).join(' ') end
- The funny
&:means "send this message"
map(&:capitalize)means "send the message
capitalizeto every item in the array"