如何解释 Ruby "end" 调用方法

How to explain that Ruby "end" invoke method

在学习 chefspec 时,我发现了以下代码:

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 调用方法 converge,我是 ruby 和 chefspec 的新手,我用 google 搜索了一下很多时间没有得到答案,有人可以帮忙解释一下语法吗?

等于:

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

在新的 ChefSpec::SoloRunner 对象上调用方法 converge

看看下面的例子,用块初始化一个对象。

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