From: Jim Freeze Date: 2002-05-24T01:08:08+09:00 Subject: Re: method_missing is cool (was: are there unit tests for cgi.rb?) On Fri, May 24, 2002 at 12:44:24AM +0900, Wakou Aoyama wrote: > Hello, > > I think method_missing is not good. because, real error is hidden. > Yes, that has been said before, but in another way. This method while compact, cannot verify correct syntax. > On Thu, May 23, 2002 at 12:20:45PM +0900, > Jim Freeze wrote: > > > puts a.h1("Title") > > puts a.a({'href'=>'http://mylink'}) { a.h1 { "Title" } } > > puts a.a({'href'=>'http://mylink'}) { a.h1 { "Title" } }, a.br > > Isn't this enough? > > def a(element, attr = {}) > "<#{element}" + attr.collect{|k,v| %Q< #{k}="#{v}"> }.to_s + ">" + > if block_given? then yield.to_s + "" else "" end > end > Yes, but you need to define it for every entity, (hr, a, body, html, tr, table, td, ul, li, ...) Hence, the method missing is a cheap way to do this repeated task with a single piece of code. I suppose that you could add the entities to a list and check for membership inside method_missing. Then you could at least verify that a correct entity was being used. But you would need more code still to verify correct attributes are being used with a particular entity. Jim -- Jim Freeze If only I had something clever to say for my comment... ~