Search This Blog

May 30, 2014

When to freeze, clone or dup in Ruby?

I try out expressing my intent in different forms to see what works effective. This time around, I'd like to story tell the code as if it's evolving over a pair-programming session. I'd appreciate your constructive feedback.

Warning the examples in story you're about to read might be super contrived and redundant. I'm merely trying the story-telling way to explain concepts with examples in the hope that you get near first-hand experience of pair-coding and experience learning. Chew on the concept leaving the contrived examples and story behind :P

May 29, 2014

Exploiting tap in Ruby

The instance method tap is available as part of Object class from Ruby 1.9.x onwards. Rubyists exploit it to different use cases for fun and fashion. This blog post is to share my thoughts on what I think tap is best for.

May 28, 2014

Require versus Load in Ruby

The big difference

  • While you load a file, you require a feature
  • Every time you load, you load a file into memory. On the other hand, every time you require you is if it has already been required to avoid repetition
  • require is more abstract an API than load. So typically for you're day to day use, you'd require not load.
  • Because you load a file, the load method takes the input argument having file extension. The file extension is excluded in the case of require method.