David said:
def foo
yield if block_given? # no point doing it the slow way
end
p foo { ["bar", "baz"] }
I have a feeling there may be something more to your question that I'm
not seeing.
Maybe this:
foo { break "bar", "baz" }
?
David
Almost. 'break' well...breaks it though, cause im recursively calling
methods >_<
Heres my original code:
-----------------------
module HTML
def method_missing(meth, attr={}, &block)
html, attrs = "", ""
attr.keys.each{ |key|
attrs << " #{key.to_s}='#{attr[key]}'" if attr[key]
}
html << "<#{meth.to_s}#{attrs}>"
html << block.call if block #yes Dave, the long way =p for now
at least
html << "</#{meth.to_s}>"
html
end
module_function :method_missing
end
include HTML
p html {
body {
div
class=>"divcls") { "IM IN A DIVLOL" }
}
}
=> "<html><body><div class='divcls'>IM IN A
DIVLOL</div></body></html>"
So far so good. But when I need multiple returns..
--------------------------------------------------
p html {
body {
div
class=>"divcls") { "IM IN THE FIRST DIV" }
div
class=>"divcls") { "IM IN THE SECOND DIV" }
}
}
=> "<html><body><div class='divcls'>IM IN THE SECOND
DIV</div></body></html>"
So now I need to break convention and use:
p html {
body {
[div
class=>"divcls") { "IM IN THE FIRST DIV" },
div
class=>"divcls") { "IM IN THE SECOND DIV" }]
}
}
Which is just ugly. The CGI lib overcomes this problem but I have no
idea how to make this work..