Blocks, Procs and Lambdas

May 15, 2012

0

Block is one of coolest features in Ruby programming language. You’ll find it almost every where in Ruby program. It’s a surprise for me if I don’t see block in a Ruby program. Block is not an object; it’s a syntactic structures in Ruby. However, we can create an object that behave like a block […]

Posted in: Ruby

The Symbol#to_proc trick and how it works under the hood

May 14, 2012

0

For example, you have an array of cities and you want to convert all elements in the array to upper case. The implementation is quite simple. We use iterator map to go through each element and invoke upcase on each element, which is a string. Finally we get an array back which all elements are […]

Posted in: Ruby

Bi-directional Association in Active Record

May 11, 2012

0

In Active Record (AR), when you specify an association in a model, usually there is an association in the associated model to the same model in reverse. Consider the following models: From the example models above, communications association on Listing and listing association on Communication are inverse of each other. By default, AR doesn’t know […]

Posted in: ActiveRecord, Rails

Active Record Callback

May 11, 2012

0

In Active Record (AR), callbacks are hooks into life cycle of an AR object which allow you to perform any action before or after an alteration of the object state. There are a bunch of callbacks in AR life cycle such as after_find, after_initialize, before_validation, after_validation, before_create, after_create, before_update, after_update, before_save, after_save, before_destroy, after_destroy, after_commit, […]

Posted in: ActiveRecord, Rails

Leaving Yoolk and What’s Next!

December 25, 2011

0

After almost 4 years at Yoolk Inc., today is my last day. (Actually my last day was Friday 23rd; it’s my bad that I could not manage to write on that day). It seems like it’s just yesterday. It’s said that when you’re having a good time, time flies really fast. It’s been an amazing […]

Posted in: Uncategorized

Invoking OS commands and forking processes in Ruby (Part II)

September 14, 2011

0

In the previous post I talked about invoking commands in Ruby program. In this post I’m going to talk about forking processes and how to use both of them together. One of the approaches to achieve concurrency in Ruby is to use Ruby multiple processes. To fork a new Ruby process use fork or its […]

Posted in: Ruby

Invoking OS commands and forking processes in Ruby (Part I)

September 14, 2011

0

When you write your program, at some point you probably want to run a command in your program. There are many ways to invoke OS commands in Ruby and each of them behave differently. Let’s start with Kernel.system. When you call it will execute the command in a shell and wait for it to complete and […]

Posted in: Ruby