[Rg 97] Re: [PATCH] Gestalt improvements

Stephan Maka stephan at spaceboyz.net
Fri Sep 21 06:29:31 EDT 2007


gabriele renzi wrote:
> correctly. But this message is just to point out how happy I am that the
> nitro community is keen on writing specs when implementing features :)

I wrote two specs. What do you suggest?

> I just have a small doubt:
>         if block_given?
>           text = yield
>           @out << text.to_str if text != @out and text.respond_to?(:to_str)
>         end
> 
> if the result of the block does not respond to to_str and/or is not @out,
> nothing happens, which could hide errors, I think.
> 
> Wouldn't it be better to just have:
> 
>         if block_given?
>           text = yield
>           @out << text.to_str if text != @out
>         end
> so that the behaviour is more fail-early?

Your suggested solution tries to invoke :to_str on the object returned
by the block. That could be an Array returned by Array#each which hasn't
a :to_str method.

When we change :to_str to :to_s we're challenged by this failure:

gestalt {
  tr do
    %w[one two three].each do |s|
      td { s }
    end
  end
}
=> "<tr><td>one</td><td>two</td><td>three</td>onetwothree</tr>"

I find the restricted environment in Gestalt due to instance_eval very
difficult to handle. Isn't there another way of pulling Gestalt's
method_missing into the invoking code without losing @out?


Stephan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/ramaze-general/attachments/20070921/a25d131e/attachment.bin 


More information about the Ramaze-general mailing list