Thursday, February 6, 2014

Week 1 Day 4: Rockin' out with Ruby

Major activities of the day: Ruby, Ruby, and more Ruby!!!  A bit about splat arguments, but mostly working with control flow (i.e. if/elsif/else and various forms of loops), plus Strings and Arrays, as well as gaining a deeper understanding of scope and how methods (and their return values) are passed around.  Today was also Flatiron's famous knot-tying workshop, led by our very own Arel English!  Homework was to make a jukebox program that responds to a variety of input commands and plays music.  Mine currently launches songs by loading a YouTube link to the song, through the "system" function.  Kinda hacky, but it works!  :)

Cool new thing I learned today: there's a convention to have a separate file which executes your program so you can run specs on your methods without having the program actually execute.  In other words, the program should be executable via a "run" method, which is called not in the program file itself, but in another program, like so:

program.rb

def run(args)
  #do some stuff
end

#helper methods


bin/program

require '../program.rb'
run(args)


This way, I can require program.rb in my specification file without the program actually running before the specs are checked.  This is especially useful for programs that usually take user input.

Skills developed: Control flow, Strings, and Arrays in Ruby

QOTD: "This is one way that knot-tying is like programming.  You're thinking about future you."  (because you'll eventually have to untie the knot, or read your code) -Avi

No comments:

Post a Comment