News for hackers. Stuff that matters.
Re:OOP practiced backwards is "POO" by patio11 on Saturday December 11, 2010 @12:53AM (#1994300)
About the only thing I use is_a? for routinely in Ruby code is to allow a particular function to accept many types of things as arguments. (An array? Sure! A single object? Why not? A single ActiveRecord id? Don't sweat it, I can do .find(id), too!)
Re:OOP practiced backwards is "POO" by aeden on Saturday December 11, 2010 @01:36AM (#1994362)
You could even do away with is_a? there and just ask if the argument responds_to a particular method and then call the method if it does. I find myself doing more of this and less of calls to is_a? these days.
Re:OOP practiced backwards is "POO" by steveklabnik on Saturday December 11, 2010 @10:49AM (#1994996)
It's conceptually much cleaner, too. If you're asking about the type of something, you're almost always just trying to see if it has some method. Just ask about the method response directly.