On Thu 23 May 2002 at 02:30:05 +0900, Wakou Aoyama wrote: > a little tricky extension. > > class HTML > def initialize(&block) > instance_eval &block > end > def method_missing(methId, data, attrs = {}) > tag = methId.id2name > tag.upcase! > attr_str = '' > attrs.each do |key, value| > attr_str << sprintf(' %s="%s"', key.upcase, value) > end > sprintf("<%s%s>%s</%s>", tag, attr_str, data, tag) > end > end > > HTML.new do > puts a('Google', 'href' => 'http://www.google.com/') # ok. > puts ul(li('item1') + li('item2') + li('item3')) # ok. > end > > puts a('Google', 'href' => 'http://www.google.com/') # NoMethodError! > puts ul(li('item1') + li('item2') + li('item3')) # NoMethodError! That's a nice extension, since it keeps the namespace clean by removing the need for the module inclusion. I wonder if anyone has a use for this code in an existing HTML module. It seems too useful not to use it. :-) Ian -- Ian Macdonald | There's enough money here to buy 5000 cans ian / caliban.org | of Noodle-Roni! | | |