do
and end
are reserved words. They have no generic higher purpose (at least until Matz goes nuts like Larry Wall and says they do). In your sample code, the external do ... end
means the code block – same as { ... }
. The internal end
serves as the right delimiter of the def ... end
method definition.
In the context of class_eval
, the code sample in the OP does exactly the same thing as:
class ::ApplicationController
def close_sdb_connection
puts "Closing sdb connection."
end
end
However, block statements, such as Foo.class_eval do ... end
significantly differ from non-block statements, such as class Foo; ... end
, as the blocks are closures over local variables.
It is interesting to note, that not each do ... end
indicates a block.