Exploring the Ruby Koans: Building an Object Proxy

Filed Under (Events, Ruby) by John Miller on 14-04-2009

Tagged Under :

Recently I started working through EdgeCase’s Ruby Koans project as a way to become familiar with the Ruby language. The Koans are a set of unit tests that you need to make pass in order to move on to the next step. In making them pass, you learn about the syntax of the Ruby language as well as some of the commonly used libraries.

To get started, follow the instructions on the Koan’s project page on github. When working through them, keep in mind that it’s not a race. Take your time to really understand what each exercise is meant to teach you.

If you’d like a little help getting started with the Koans, one of the author’s, Jim Weirich, will be helping folks at the next Cleveland Ruby user group meeting. Jim is a leader in the Ruby community (active contributor to both Rake and RubyGems) as well as a phenomenal teacher. If you have the evening free, I’d really recommend coming to hear him talk! And in addition to the awesome upcoming CleRb session with Jim Weirich, one of the local .Net SIGs will be featuring Michael Letterle later in the month who will be speaking on IronRuby. Looking forward to both of these events!

In one of the more challenging exercises, you’re asked to build an object proxy that you can wrap around another object to intercept and track method calls made to the underlying object. Below is the solution I came up with (you may want to quit reading if you plan on doing the exercises yourself!). I’m not sure it’s the most elegant solution but it did get the tests passing!


class Proxy
  def initialize(target_object)
    @object = target_object
    @message_log = {}
  end

  def method_missing(method_name, *args, &block)
    if @object.respond_to?(method_name)
      @message_log[method_name] = number_of_times_called(method_name) + 1
      @object.send(method_name, *args, &block)
    else
      super(method_name, *args, &block)
    end
  end

  def messages
    @message_log.keys.reverse
  end

  def called?(method_name)
    @message_log.key?(method_name)
  end

  def number_of_times_called(method_name)
    @message_log[method_name] || 0
  end
end
DotNetKicks Image

Share/Save/Bookmark

Nothin’ But .Net – Experience of a Lifetime

Filed Under (Events) by John Miller on 26-11-2008

Tagged Under : , ,

Last week, I had the opportunity to attend one of Jean-Paul Boodhoo’s infamous .Net Bootcamps. And it, by far, exceeded it’s reputation as one of the most intense (and rewarding) .Net courses available. We started each day at 9:00 AM and the earliest we got out on any night was 11:00. In fact on Thurs. evening, I didn’t make it to sleep until 3:30 the next morning (and I was one of the slackers who went to bed *early*).

JP compacted what felt like 6 months of learning into one week, demystifying some topics that I’ve struggled with in the past (everything from lambdas to the intricacies of fluent interfaces). The week was spent creating a storefront from the ground up using no 3rd party frameworks. This meant creating our own front controller, dependency injection container, ORM, etc.  And that was all in just four days. The first day was spent going over the prep material (yes, we had homework to be done before the class) & and an in depth review of fluent interfaces.

Beyond the intense curriculum, I think we all took away a lot of good life advice as well. Those of you that follow his blog know that JP has a very unique and refreshing outlook on life. Kinda Tony Robbins meets Scott Hanselman. One of my favorite quotes was “Keeping up with the Joneses is a defeating task”. He stressed that we need to set goals for ourselves that are independent of what everyone else is doing. Focus on the technologies\ideas that we’re passionate about and ignore the rest. He also pushed the idea of “trimming the fat” to reduce the distractions that slow us down. Context switching (multi-tasking) affects focus and can keep you from doing your best work. For me, his productivity and motivational tips were just as valuable as the technical knowledge.

It was also a huge privilege to work with some of the other students in the class. Definitely a humbling experience to be working not only with JP, but some of the sharpest developers of our time. We spent most of the last two days pair programming, which was a first for me. And I was surprised at how much better our code base was because of it.

While we were split into small groups, JP would regularly give us partially finished segments of code and we would have a race to the death to see which group could check in a working solution the fastest. Once someone checked their solution in, JP would politely smile and praise the group on their success. Then, in classic JP fashion, he would begin to show us how he would have solved the problem by refactoring the submitted code. By the time he was done, the code was more elegant, easier to read, and usually looked nothing like what was submitted. Humility was a concept we all grew to know very well.

One of the many surprises of the trip was the awesome food. While he pushed us harder than what most state laws will allow, he also treated us like royalty. We ate at a couple of the swankiest restaurants in Philadelphia. Nothin’ but .Net…and lobster ravioli, stuffed mushrooms, and pumpkin cheesecake. Much of the credit has to go to Brian Donahue for making some phenomenal dining selections!

This was by far the best money I’ve ever invested in my career and would STRONGLY recommend it to anyone looking to take their skill set to the next level. In fact, I’m planning on taking the course again next year. He goes through so much that, while you definitely leave with a MUCH better understanding of proper software design than when you arrive, it’s impossible to grasp it all in one week.

I would recommend that anyone interested in the course check out his blog and read some of his past posts (the ones under the “Inspiration” category are personal favorites).

And if you’d like to read some more reviews, check out:

Looking forward to the next one!!

Reblog this post [with Zemanta]

Share/Save/Bookmark