All posts tagged: ruby

Using blocks in Ruby for lazy evaluation

programming

I’ve been working on a templating engine recently and had the need to substitute some variables on the page with the result of an slightly expensive remote API call. The first iteration was just a simple replace on the page: [crayon-5f706d6d98c8d359241832/] This “worked” but the problem is the call would be made even if the variable that needed replacing wasn’t on the page. The easy fix is to check it exists before making the substitution: […]

Law of Demeter and the delegate method

computing / rails

The Law of Demeter, or Principle of Least Knowledge is a fairly simple design pattern, which, simply put means that an object should only talk to it’s immediate “friends” The law states that a method M of and object O may only invoke the methods of the following kind: 1. a method on O itself2. any parameters passed to M3. any objects instantiated within M4. any direct components of O The classic example coined by […]

Vlad 2.0 Not Finding Tasks in deploy.rb

computing / programming

When I restalled all my gems on Snow Leopard, vlad refused to find any of the tasks I had defined in my deploy.rb. I thought this was a SL issue but turned out a week before it’s release Vlad had been updated to version 2 which used a new plugin system. Looking for vlad rake tasks returned an error: To solve the problem just required an install of the new vlad-git gem. Now all my […]

The Code Shall Set You Free

computing / programming

I was recently asked why I don’t comment my code. It’s a fair enough question. There was a time when commenting your code was the done thing. I was once a great believer in commenting code as much as possible and would bash those that didn’t, but now I vary rarely comment my code at all. In my current project of over 1,500 LOC, there are only a handful of comments. Many people will argue […]

rake spec fixtures failing

programming / rails

For some reason my rspec fixtures were not loading into my development database when doing spec:db:fixtures:load. An extra parameter to db:fixtures:load is all that’s needed. [crayon-5f706d6dad06b574409181/] Fixed by: [crayon-5f706d6dad070442694670/]

RSpec + Autotest + Growl + Doom Guy

computing / programming

I spent this morning playing around with autotest, but was getting really flaky results with the Growl notifications. I tried about four different autotest configs, but none of them seemed to consistently worked. I remembered that the Growl notifications at Thursday’s Coding Dojo worked pretty well, so after some digging around I found the config on their github. After a tiny tweaking I was even able to get it to work with Przemysław Kowalczyk’s Doom […]