Closures in Ruby
February 15, 2012
The complete title for this post is: Closures in Ruby make my head hurt. I’ve had a rough idea of how closures work (from my JavaScript experience), but I just watched An Introduction Blocks, Lambdas and Closures in Ruby and I’ve realized that I my knowledge is a mere drop in the ocean. I would [...]
Alias class methods in Ruby
February 14, 2012
Yesterday I came across a problem where one possible solution was to alias a class method. I’ve blogged about aliasing methods before, but I didn’t know how to do this for class methods. Turns out, it’s pretty simple – the syntax is just a bit different. class Person def self.all %w{ Bob Steve } end [...]
Using Zip in Ruby
February 13, 2012
Last week I blogged about the Enumerable module in Ruby and specifically mentioned the Enumerable#zip method. I didn’t think the zip method was particularly useful, but I have actually found a few extra features which are very nice. To refresh your memory, the zip method will combine the elements of two different arrays. names = [...]
Presence of a substring in Ruby
February 10, 2012
I just watched the ‘Ruby Trick Shots’ video. This video basically shows a bunch of very useful methods, libraries and techniques you might be unaware of. If you’re a Ruby developer I would highly recommend it. One of the ‘tricks’ I found particularly interesting was checking for a substring. Let’s say we have the following [...]
For vs Each in Ruby
February 9, 2012
One of the discussions I was involved in at RubyFuza revolved around the difference between for and each in Ruby. There is only a subtle difference around scoping, but I think it’s an important distinction because it reveals some important aspects of Ruby. The for loop is a syntax construct, similar to the if statement. [...]
Exploring Enumerable in Ruby
February 8, 2012
One of talks I was able to attend at last week’s RubyFuza conference was by Andrew Timberlake titled ‘Ruby’s Hidden Gems’. It basically revolved around examples of how we often implement something in Ruby that is already supported in the API. I’ve blogged about this before – how I found myself writing C# code, but [...]
RubyFuza 2012
February 7, 2012
Last week I was lucky enough to be able to attend the RubyFuza conference in Cape Town, South Africa. As far as I know this is the biggest Ruby conference in South Africa and when ThoughtWorks offered me the chance to attend I grabbed it with both hands (even though it’s a long flight from [...]
Checking if variables are defined in Rails Partial Views
January 31, 2012
During this week I was working on a Rails app when I ran into an issue where I needed to check if a variable has been defined in my view. The standard way to check if a variable is defined in Ruby is with the defined? operator. defined? name # nil name = “Bob” defined? [...]
Book Review: Programming Ruby
January 27, 2012
TLDR Version: This book is incredibly well researched and covers pretty much everything in the Ruby world. While it does have a very good introductory section I think the main benefit to this book is as a reference guide. Programming Ruby is probably the most well-known book in the Ruby world. I guess I’m a [...]
Method Resolution in Ruby
January 26, 2012
While reading the Ruby Pickaxe book I realized that while JavaScript and Ruby are both dynamic languages, they handle method resolution in very different ways. I often use JavaScript as a reference since it’s the dynamic language I’m most familiar with. A Simple Example in JavaScript Let’s first look at a simple JavaScript example. var [...]