How To Explain That The Ruby End Call Method

When learning chefspec, I found the code below:

describe 'example::default' do
  let(:chef_run) do
    ChefSpec::SoloRunner.new do |node|
      node.set['cookbook']['attribute'] = 'hello'
    end.converge(described_recipe)
  end
end

end calls the method converges , I'm a little new to ruby ​​and chefspec, and I have a lot of time on googled and did not get an answer, can anyone help explain the syntax?

+4
source share
2 answers

This is the same as:

x = ChefSpec::SoloRunner.new do |node|
  node.set['cookbook']['attribute'] = 'hello'
end
x.converge(described_recipe)
+6
source

The method convergeis called for a new object ChefSpec::SoloRunner.

Take a look at the following example of initializing an object with a block.

Array.new(4) { 5 }.length
# => 4 
Array.new(4) do
  5
end.length
# => 4
Array.new(4) do
  5
end.class
# => Array 
+5
source

All Articles