Widgets _always_ receive a block, even if one is not given in an
initializer, and even if the initializer does not define a block
parameter. This is very surprising behavior, and I hope it's a
bug—otherwise, it would be impossible for a Widget to tell if the user
created it with an actual block.
class TestingWidget1 < Widget
def initialize &optional_block
if block_given?
para 'This block was given to me: ', optional_block.inspect
else
para 'A block was not given to me. In other words,
optional_block == nil'
end
end
end
class TestingWidget2 < Widget
def initialize &optional_block
if block_given?
para 'I got a block, even though I should not have one!'
else
para 'I did not get a block, which is what should happen.'
end
end
end
Shoes.app do
testingwidget1 do
para 'I am inside a block.'
end
testingwidget1
testingwidget2
end
Sinecerly,
Joshua Choi