Learning? Read Split-s. #
Split-s, a nice blog for getting down some basic Ruby concepts. The code here on RedHanded can be pretty heavy handed sometimes—I’m completely out of touch with each of your pressing needs—so I’ll defer to split-s when it comes to topics such as conditional initialization. Which culminates in an explanation of this snip:
def addToList(key, value) (@map[key] ||= []) << value end
Martin also codes in Java—expect some comparisons. If you lack know-how on duck typing, take a gander at yesterday’s Quack, Quack.
zenspider
much more readable, doncha think?
norseman
In some ways yes. But is there some sort of advantage, aside from speed, to the other method?
flgr
Sometimes you can’t define initialize by yourself. Modules in their Mix-In roles have a hard-time initializing stuff, for example, which is why they usually use the lazy initialisation technic.
Another advantage might be that you can skip initializing stuff that you aren’t going to need anyway. Which might be important if said initialization is very expensive.
Comments are closed for this entry.