What does "exit_on_fail("initialize") { hook('preinit') { preinit } } " mean?

Hi,

I am a newbie for ruby,and not much familar with rube’s grammar although
I
promise I have read some ruby books. When I read puppet codes, I find
the
following snippet:

This is the main application entry point

def run
exit_on_fail(“initialize”) { hook(‘preinit’) { preinit } }
exit_on_fail(“parse options”) { hook(‘parse_options’) { parse_options }
}
exit_on_fail(“parse configuration file”) { Puppet.settings.parse } if
should_parse_config?
exit_on_fail(“prepare for execution”) { hook(‘setup’) { setup } }
exit_on_fail(“configure routes from #{Puppet[:route_file]}”) {
configure_indirector_routes }
exit_on_fail(“run”) { hook(‘run_command’) { run_command } }
end

I can’t understand why "exit_on_fail(“initialize”) { hook(‘preinit’) {
preinit } } " can be part of a statement together. I looked through some
ruby books, but found no answer.

I know that run(), exit_on_fail(), hook() and preinit are all the method
of
the same class.

Thanks
Yunfeng

Yunfeng Xu wrote in post #1024181:

I can’t understand why "exit_on_fail(“initialize”) { hook(‘preinit’) {
preinit } } " can be part of a statement together. I looked through some
ruby books, but found no answer.

Read a section about ‘blocks’. e.g.
http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_containers.html#S2

Here you’re not passing a block to be iterated (called multiple times),
but something to be called later on.

class Foo
def prepare(&blk)
puts “I got a block! I’m going to run it later”
@my_block = blk
end
def doit
@my_block.call
end
end

f = Foo.new
f.prepare { puts “Goodbye cruel world” }
puts “OK it’s stored”
f.doit

Thank for Candler. I have gotten it.

For other newbies like me, I suggest read the book “The Ruby P.ming
Language” that has many details about block grammar.