Search This Blog

May 19, 2012

Agile Tour 2012 - Bangalore, India

Agile Tour 2012 would be my first Agile conference that I'll be speaking this year, very closely followed by Agile By Example 2012 conference in Poland.

At2012_speaker

Because the timing of the said conferences are very close, I shall be speaking on the same topic and it is "How I hated the ceremonial standup and how I ended up enjoying it."
If you are around to any of these conferences, feel free to get in touch; we'll talk and share our experience.
Thank you ISEC for accepting my proposal!

Agile By Example 2012

I'm glad to announce that...
300-250-sp

Should you wish to know what I'd be talking about, and what other speakers have to share, do browse Speakers List.
See you there...

May 13, 2012

Rails and StringInquirer - A real world example

Use Case:
Assume a User model, having an association with UserProfile model. Also, presume that Admin, Artist, Exhibition Curator, Collector, etc are models that are inherited from UserProfile.

Now, if we'd like to know weather a given user is an admin or a collector or of any other profile type, we'll typically have to define methods like below in the User class:
We coule simplify the above methods using meta-programming technique to define methods at runtime, using "define_method" method.

However, there exists an easier and neater method. It is to employ the delegate and StringInquirer as below:
With any of the above implementations, we can test a given user instanse against a specific user profile type as below:
user.admin?
instead of
user.user_profile.type.titleize == "Admin"
As a matter of fact, starting Rails 2.3.x, if I'm right, you test for Rails environment with a code like the one below:
Rails.env.development?
instead of
Rails.env == "development" 
or
RAILS_ENV == "development"
Usage of RAILS_ENV and other such constants were depricated with Rails 2.3.x and completely removed beginning Rails 3.x

Lesson: For better code readability, wrap your string value with StringInquirer, especially in cases like the above examples.

It is good to know that StringInquirer is infact a sub-class of String, and that the above magic of boolean returning methods is achieved by way of method_missing implementation in the StringInquirer class.

Resources: