Hello,

On Wed, May 22, 2002 at 06:09:37AM +0900,
 Ian Macdonald wrote:

> require 'html'
> include HTML
> 
> puts a('Google', 'href' => 'http://www.google.com/')
> puts ul(li('item1') + li('item2') + li('item3'))

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!


-- 
Wakou Aoyama  <wakou / ruby-lang.org>