From: Austin Ziegler Date: 2005-01-20T06:37:15+09:00 Subject: Re: is defined? fast? On Thu, 20 Jan 2005 05:52:59 +0900, Bill Kelly wrote: > From: "Austin Ziegler" >> unless defined?(Text) >> module Text; end >> end >> >> class Text::Format >> ... >> end >> >> Saves me some indentation levels and keeps the code readable and working. > Is the top part semantically different from just, > > module Text; end > > ? irb(main):001:0> class Text; end => nil irb(main):002:0> module Text; end TypeError: Text is not a module from (irb):2 irb(main):003:0> It's simply defensive programming. I could shorten it with: module Text; end unless defined?(Text) I haven't done this with all of my libraries, but mostly on those libraries where I am using the module as a namespace (e.g., Text::Format, Text::Hyphen, and now Kaspar's Text::Reform). It's not perfect, but it's better than it could be ;) -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca