The Book, Day One


The Introduction chapter makes Ruby (and Rails) seem like something magical, not a programming language. I guess it’s partially marketing lingo.

Appendix A, Introduction to Ruby

It suggests reading through Appendix A, Introduction to Ruby. Since my only exposure to Ruby is copying code from existing scripts at work, I figured that I should read it. The content so far is ringing a bell, but it is making a lot more sense than it did when I was just randomly trying to figure stuff out at work and wondering why it didn’t work.

My confusion over why some words were prefixed with a @ symbol has ended. Those are class variables.

I like the idea of using symbols to identify things, such as method parameters. I tend to do that myself when I’m writing PHP code, to make it more readable as to exactly what a random string thrown at a method as a parameter is meant to do. But Ruby has that built in. Writing

:type => "add"

would send the string “add” as the value for the method parameter type. So cool!

Something that still weirds me out though is using “end” instead of a } to close out a method or class definition. And the 2-space indentation instead of 2. And no semi-colons. I guess I’ll get used to those ideas by the end of the term…

Ruby deals with strings sort of like PHP does. If you’re using single quotation marks, it does a lot less processing. But with double quotes, it does substitutions. In PHP, you could do this:

"Hello {$name}! Welcome to my site."

And it would parse the value of $name and insert it there. (Granted, you can also do $name without the curly braces, but that’s not as clean to read.) You can also do this in PHP:

"Hello {$person->getName()}! Welcome to {$config['sitename']}."

(You can also use some functions on an object or render the value of an array. This will generally also work with an object that has a magic __toString() method.) In Ruby, you can also do this sort of thing! Example:

"Hello #{person}"

I love how the evaluation of the last expression in a method is effectively its return value. It reminds me a bit of VB from Excel macros, but I can deal with that for its awesomeness.

Okay, I think that’s all my Ruby learning for today. I will pick up where I left off at some point tomorrow, mixed in with packing time since classes start on Monday! And we have the first team meeting tomorrow afternoon.


No Responses Yet to “The Book, Day One”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: