Gray's Matter
Justice Gray - North America's favorite metrosexual software consultant

I Wish These People Updated More Than Once a Year

"I envy your hair.  Is that a dominant gene?"  It's lines like this below that convince me that if I ever was sired from a different father, that father would have obviously been William Shatner.  Don't get me wrong, my dad is awesome with a capital ~! (I mean, he and my mom are pretty much responsible for all of my genetic material); however, I am sure Mr. Shatner would have made an excellent stunt double at my conception if needed.



Anyway, I figured there needed to be one central location that linked all of the Ruby screencasts together along with explanatory text, so here they are!  All of these screencasts require the TechSmith capture codec.  As well, they are all silent because either
a) I used them as backdrop while I presented at Edmonton Code Camp or
b) because this gives them a classic feel much akin to the silent films of the 20s and 30s

Pick whichever explanation makes you feel better about watching these!  All of the demos were done using Notepad++ and Console - if you're curious about those I recommend taking a look at my brief Tools screencast that shows off these and some other tools.

Posts in the Ruby 101 series are listed below.

  1. Thanks a lot, Leon Bambrick - a familiar application with a special twist ending; I risked divorce to get this out to you guys!
  2. Didn't we see this before? - similiarities Ruby shares with Perl and then some things that make Ruby quite a bit different from Perl and a little more like LISP
  3. What's a block? - get a look at the main construct in the Ruby language
  4. Classes and more - see how classes are done in Ruby using the Donald Belcham lightsaber example
  5. Adding functionality with decorators and mixins - Soundwave and Laserbeak show why decorators are trivial, but decorators aren't the only way to add functionality in Ruby!
  6. Miscellaneous coolness - attribute readers and writers, Excel automation and a discussion on duck type unit testing
  7. Method rewriting - one of Ruby's most powerful features explained!
Enjoy the screencasts!


Friday, November 10, 2006 #
Comments [0]   Ruby | Technical  | 


We conclude the Ruby 101 series with a look at one of the most powerful (and one of my personal favorite) features of Ruby: dynamic method rewriting.  In this screencast, we will take a look at how attr_reader and attr_writer actually work, by defining our *own* attr_reader and attr_writer.  After that, we'll take a look at how to write a cached accessor method. 

What's a cached accessor method?  Well, let's assume that we've got a method call in C# that looks like this:

public string ReturnOurValue()
{
    // time-consuming calculations follow
    return ourCalculatedValue;
}

Many of you would probably do something similar the following to avoid doing the time-consuming calculation all the time:

public int DoCalculation()
{
     if (this.CalculatedProperty != null)
     {
       return this.CalculatedProperty;
     }
     else
    {
       string ourValue = // various time-consuming calculations
       this.CalculatedProperty = ourValue;
       return ourValue;
    }
}

That's just fine, but what if we have several different time-consuming calculations?  Do we have to duplicate this logic every time we want to cache our accessor?  Ruby allows you to do this as easily as attr_reader - this screencast will show you how!

Although this is the final chapter of the existing screencasts, I'm aware that I've promised to put up some screencasts in the future that explain other facets of Ruby, such as:
  • setting it up
  • a look at alternative IDEs
  • TCP/IP work

Trust me, these *are* coming!  In the meantime, please feel free to download the seventh screencast!  I definitely hope you have enjoyed the series.  If there are any other facets of Ruby you'd like me to explore, please drop me an E-mail or leave a comment; I'm happy to do more of these and they can also go towards my presenting on this technology in the future.

Thanks everyone!

Thursday, November 09, 2006 #
Comments [0]   Ruby | Technical  | 



This should've gone with the mixin post, but it still looks so delicious!!  I miss you, ice cream...

Our penultimate entry in the not-so-regularly scheduled Ruby 101 series brings us a large variety of different topics, some of which will be strikingly familiar to anyone who has read "Programming Ruby":

  • Attribute Shorthand in Ruby
  • Ruby's Built-In Bechmarking
  • Easy Excel Automation in Ruby
  • File Handling in Ruby
  • Duck Typing and Unit Testing
Download the screencast here
(Note: like all of the screencasts before it, this requires the Camtasia/TechSmith capture codec)

Tuesday, November 07, 2006 #
Comments [0]   Ruby | Technical  | 


Laserbeak - the star of this screencast
Laserbeak - the star of this screencast

Screencast mania @ Gray's Matter continues with the latest installment of our Ruby 101 series!  Now that we've discussed  how you can modify anything, we'll look at a couple of other ways to add run-time and design-time functionality to our classes!  Our first example uses Laserbeak the Decepticon to show how trivial decorator implementation can be in Ruby, and then we follow up with Ruby's answer to multiple inheritance, the mixin!

Download the screencast here!


Wednesday, October 25, 2006 #
Comments [3]   Ruby | Technical  | 


With a new day dawns another 5 minutes of Ruby tutorials!  Today's silent screencast covers the following:

Classes in Ruby
Property getters, setters, constructors, inheritance, you name it!  We go over it in a simple example using Donald, Justice, the EDMUG executive and the all-important "hair" property.

Some supplements here:
  • super indicates a call to the parent class
  • < indicates an inheritance: e.g. "Donald < EdmugExec" means Donald inherits from EdmugExec
  • @variable_name indicates an instance variable of a class
Easy reflection in Ruby
Take a look at how quickly we can receive class information in Ruby!  Just ask and it is given.

Hooks
The simulation of the EDMUG executive continues!  Art imitates life as Donald finds there are just some things he can't do, so he gets Justice to do them for him...in this case, using the method_missing hook to delegate failed requests to a different object!  (This will tie in later to an interesting decorator implementation - stay tuned!)

A note here: you'll notice that method_missing is implemented using the following syntax:
def method_missing(method, *args, &block)

The * behind an argument in Ruby means that there are a variable number of arguments.  The & prior to an argument in Ruby converts a block (if there is one) into a Proc object. 

You can modify anything in Ruby
What happens if we want to add the infamous swinging lightsaber method to the Donald class at run-time?  What if we just want to add it to one *instance* of the Donald class?   Anything is possible!!

You can modify anything in Ruby, so let's not get retarded
I don't think this needs any further explanation ;)

If you somehow missed the link above, download installment 4 right here!


Wednesday, October 18, 2006 #
Comments [3]   Ruby | Technical  | 


Now that Mrs. L days are over, we continue our largely silent screencast series with an explanation of "the block", which you would've seen at the tail end of the previous screencast.  A couple of supplemental notes:

the ! operator (as seen in the collect! method call) indicates that the method we are calling is destructive - whichever object calls the method will have its contents altered.  This is a de facto standard in Ruby - if you define an object that has a destructive method, said method should have a ! at the end.  Non-destructive methods return a copy of the object and thus do not have the !.

yield, when seen in a method, calls whatever anonymous method was passed as an argument.  This screencast shows it both a simple example and also how to define your own each method on a class.

Finally, the lambda operator takes a block as an argument and creates a Proc object out of that block; this has the effect of preserving any context of the block, as we'll see!

Download part 3 here!

Wednesday, October 11, 2006 #
Comments [0]   Ruby | Technical  | 


Part 2 of the "Silent Screencast" shows us some of "deja vu"ish functionality of Ruby, and finishes with an exploration of why Ruby is very different - because *everything* is an object.  No, we mean everything and the end of this video will show you why!

Download Part 2 here (you'll need the Techsmith Capture Codec to view; hopefully my actually providing these instructions makes it easier for some.  Sorry about that guys!)

Friday, October 06, 2006 #
Comments [0]   Ruby | Technical  | 


All right.  As a result of none other than Secretgeek himself commenting here, I decided that it might be better if I actually recorded some audio against these screencasts.  Unfortunately, Camtasia will *not* record the output of a pre-existing AVI file, instead choosing to display a blank, black screen!  DubIt doesn't work either, given the initial video output was intentionally fast; after all, I had the luxury of being able to pause, rewind, and fast forward during my presention. 

My initial thought was that I should re-record the entirety of these screencasts only with my talking over top of the video.  In fact, I would have done this if it were not for several problems:

  • re-recording these with audio drives up the file size like *mad* in Camtasia; from 1 meg to *53*!!
  • I wasn't too sure if the world was ready to hear just how arousing my voice actually is; I get enough riots as it is over my good looks and this would probably compound my difficulties.  Trust me, I've got enough stalkers already, I don't need any more!
  • most importantly, we are in the middle of a festival called "Mrs. L Days" in the Gray household - and my wife politely informed me that a) she thought I was done sexing up that Ruby b!tch and b) it was perfectly fine for me to continue working on these audio screencasts during the festival as long as she could rip off my testes and hang them from our ceiling.  Sorry to my audience, but I *do* love my testes more than I love my blog, believe it or not!  Thus, there will *not* be any screencasts with my voice on them until at least a week from now.

Here is the initial silent screencast of IRB, finishing on Hello World with a twist!!  Yes, it is somewhat Charlie Chaplin-esque but I like to think it adds to its charm - that and the ridiculously rapid-fire nature of a video sped up to twice its normal frame rate.  That's right, I'm not wasting any of your time with *THIS*!!!

Download the first lesson here!


Thursday, October 05, 2006 #
Comments [8]   Ruby | Technical  | 


(For those of you who were at our presentation at Edmonton Code Camp on the 30th, you can skip this; it's pretty much a similarly worded version of my introduction there).

What is Ruby?

Ruby is three things:

  • It is dynamic - so dynamic, in fact, that Ruby is the 5 dollar whore of programming languages*; you can do pretty much *anything* you want do it with very little cost and Ruby will *like it*. 
  • It is clean - Ruby's general design lends itself to fairly short methods, and much of the support in its library veers toward making your code a lot simpler and reducing its line count drastically.  I've heard it said many times that Ruby, as a language, definitely gets out of your way; a lot of the repetitive typing you have had to do in other languages is abstracted away from you in Ruby so that you don't really have to deal with it.
  • It is popular - trust me, Ruby will help you win friends and influence people.  You can't walk down the street these days without some guy offering an "Our Voice" and then asking if you've heard about Ruby! 

In addition to these three, Ruby is definitely proof that opposites attract!  After all, "dynamic, clean, and popular" sounds like the complete antithesis of the stereotypical computer scientist.

Now, aside from being the five favorite fantasy objects of Steven Rockarts, what do these things have in common?

RubyTheIntro_5FantasyObjects.jpg

They all originated in Japan at least a decade ago!

That's right - Ruby is *ancient*.  It's older than Javascript, and probably just as old as Netscape 1.0.  A lot of people seem to think of Ruby as that hot new import model...

Subaru.jpg

but it's actually a heck of lot closer to this:

tcrown_paris.jpg

So, why is it that we're only hearing about Ruby now, vs. in 1995 when it was first released?  Truthfully, Ruby is popular right now because of the flexible web framework, Ruby on Rails.  Rails was brought to the world by the guys at 37Signals, famous for Backpack, Basecamp, and (to paraphrase SecretGeek) its members looking like a bunch of pouting artists.  I won't be covering Rails in this series of screencasts, but I may do it afterwards if there are enough popular requests for it!

So, why Ruby? 

1.  Religious wars are sexy. 

You've been there for Java vs. C++, Java vs. C#, C# vs. VB.NET, and VB6 vs. *everybody*, but mark my words - Ruby vs. NET (and by extension, compiled vs. dynamic languages) are the next great religious war.  Whether you're a Ruby programmer who laughs at all those .NET suckers working for "the man", or a .NET guy who is tired of all these weed-smoking Ruby hippies with their Macbooks and their "free love", you'll have a better chance of winning that flamewar on CodeProject if you are armed with the facts.  This series will hopefully help you in that regard.

2.  Ruby == ++sexual_charisma

Yes, Ruby most *definitely* enhances your appeal to the opposite sex.  People who are familiar with this blog know that I *never* make a statement of ridiculous hype without the facts to back it up.   Below is my proof!

Here is a photo of Steven Rockarts before getting involved with Ruby.

Steven Rockarts

Here is a photo of Steven Rockarts after getting involved with Ruby.

Steven Rockarts

Yow~!  Sorry, ladies, he is taken. 

Most of you reading this have resolved to quit your jobs, join a commune and start developing in Ruby immediately.  However, for the few of you who weren't inspired by the reasons above, tomorrow we will get into coding in Ruby, complete with screencasts and IRB.  It's a hello world example with a *SHOCK ENDING*!!  Trust me, "24" has nothing on this!!

* no offense meant to any 5 dollar whores in my readership

Wednesday, October 04, 2006 #
Comments [9]   Ruby | Technical  | 


First of all, *thank you* for all the wonderful feedback that Steven Rockarts and I received on our talk at Edmonton Code Camp!  Steven has said he feels like the prettiest girl at the school dance, and I have to admit that my sentiments are similar except I prefer wearing men's clothing to dances. 

Based on the feedback that I've received, I'm going to do a couple of things.  For those of you who want it all and want it now, this post will supply the entire 30 minute screencast I was using.  For those of you who either feel a little more patient or don't really have the time to watch 30 minutes of code typing, I will be doing a series of posts this month basically breaking apart the presentation piece by piece along with a smaller bit of the screencast every day.  But that's not all!  To answer some of your other requests, I will be throwing in never-before-seen posts and/or footage of the following:

  • setting up Ruby
  • exception handling in Ruby
  • TCP in Ruby
  • a bit of talk around Ruby IDEs

I used Camtasia to record my screencasts, so if you want to view these things properly you'll probably need to use the TechSmith capture codec

Without further adieu, here is the screencast!!  Enjoy, and soon we will begin our odyssey...




Tuesday, October 03, 2006 #
Comments [2]   Technical | Ruby  |