Casper Deseyne
Casper Deseyne

Reputation: 331

What does this structure mean in Ruby?

I'm trying to learn Chef but I'm having some difficulties understanding what this Ruby code does.

web_app "helloworld" do
  server_name "hello.world"
  server_aliases ["www.hello.world"]
  docroot "/var/www/helloworld"
end

From what I understand, the first line calls web_app with the argument "helloworld" but I don't get what the do stands for in this context, does web_app return a list? When I see a list iterator in Ruby the value is passed like this do |v|. I'm guessing it's not iterating as it would make little sense to execute that code multiple times.

Upvotes: 0

Views: 120

Answers (1)

tessi
tessi

Reputation: 13574

do and end encapsulate a block in ruby. you may pass a block to every method call if you wish. It is up to the method what to do with the block.

Most methods don't care about attached blocks, but the web_app method seems to call the block to configure itself.

If you want to dive into that, here are some pointers:

Upvotes: 5

Related Questions