CSCI E-168 Building Web-Based Software with Ruby and Ruby on Rails [Intro and CH 1, 2, 6, 7, 4]


I decided to take the Ruby and Rails course because it's been one of those things that I haven't gotten around to. I feel like I'm so used to Python that picking up Ruby would make me uber confused as I'm sure I'll still work on my python-google projects and want to work on a few Rails things as well.

Will this help me find a job? Who knows (I think several students come in thinking it will). What I do hope is that it will help me get into Harvard Extension's Graduate program though.

My prior experience with Ruby is from 2005 or so. I was working on a military project and wanted to try building the multi-million dollar program in a developer-friendly framework (let me tell you it's not Struts). I discovered Ruby from the beautiful Poignant Guide to Ruby and eventually found Rails from several hyped Slashdot articles.

At the time, I built a few sys-admin tools using Ruby and probably bought the very first edition of the Pragmatic Series (pre-released in PDF form). My manager didn't quite trust a framework that hasn't reached the "1.0" milestone. Everything was going really well until I discovered Python and the Django framework. I kind of liked how Django wasn't spammed on Slashdot every day and I wanted to write the Poignant Guide to Python. Ruby already had it's celebrity (_Why)!

Since then, I haven't looked back and now that I do it's a whole new world.

Chapter 1: Getting Started

  • The first chapter covers installing Ruby and the command prompt.
  • There's a bit on the Interactive Ruby shell (irb).
  • Ruby programs use the .rb file extension.

Chapter 2:

  • A Class followed by the new method accesses it's constructor.
  • Ruby supports interpolation with #{ expression } to place code within strings.
  • Methods start with the def keyword and is closed with the end keyword.
  • Most variables start with a lower case letter (a convention).
  • Global variables start with a $, example $global_var_name.
  • Instance variables start with @, example @instance_var_name.
  • Class variables start with @@, example @@count_of_fingers.
  • A ruby hash supports any object as a key.
  • Ruby provides shortcuts to build arrays and hashes with the [] and {} symbols.
  • Ha, there's millions of shortcuts including %w{} to build an array of strings.
  • You can create a hash with a default value with
Control Structures
  • Blocks all close with the end keyword, but there's a shortcut to use {} to create a single line block.
  • while line = gets {} is an interesting block because first "line = gets" occurs before the while condition is evaluated. The conditional is actually while (line) after the input is retrieved.
  • It's possible to place the if or while condition after the statement for brevity.
  • Yields are mentioned and I am confused...

Chapter 6: Standard Types
  • It is possible to handle rational and complex numbers. (I hope I never have to!)
  • You can cast a string as an integer with: Integer(some_string)
  • Ruby always tries to return the most natural result for an expression.
  • Working with numbers is just plain awesome:
25.downto(20).with_index { |num, index| puts "#{index}: #{num}" }

  • Interpolated code can consist of multiple lines!
  • There are shortcuts for creating strings, %q or %Q or %{}
  • Here documents allow you to wrote large blocks of text in your ruby files. Basically you define a label to start and end a chunk of text.
  • The Ruby String class has over 100 standard methods.
  • There are two types of ranges, inclusive (..) and exclusive (...). Both include the first number.
  • You can use ranges in conditions, to test if a number falls in a range.

Chapter 7: Regular Expressions
  • Not a fun chapter to read, but I'm sure it will be resourceful. The stuff covered here is pretty darn complicated.
  • Luckily there are plenty of Ruby conventions to allow you to perform common RE tasks.

Chapter 4: Containers, Blocks, and Iterators
  • Arrays hold references, not copies of objects.
  • You are allowed to use negative indexes and ranges to splice data.
  • Arrays themselves have tons of useful methods.
  • To loop through an array you can use the following syntax, though I think there's also a python way using a for loop.
[1,2,3].each do |num| puts num end