what we blog

Ruby tricks: in need of rescue

Throwing exceptions is nice, but handling them can get a bit of a chore. One of the main reasons: constant reindenting of your code because you insert or remove a begin end section. While your text editor should be able to cope with that just fine, reindenting is just a mess in source control. But, for trivial cases, we can call Ruby to the rescue!

Read more

Ruby tricks: detect evaluation of default arguments

Default arguments are an often used feature of the Ruby programming language. Their basic syntax is simple:

def foo(bar = nil)
  bar == nil
end

This gives us two ways to make sure that foo evaluates to true:

a = nil
foo #=> true
foo("a") #=> false
foo(a) #=> true

Curious as we are, there is one question left: How do we detect whether the caller passed no argument or that he passed an argument, which just happened to be nil?

Read more

Ruby tricks: introduction

Its one of our hobbies and thats why it became launch categories as well: weird ruby tricks. This category will show small ruby tricks that allows you to take a glimpse at how the language works. Some of them are useful, some are not, but usually fun...

Read more