0

我无论如何都不是 Ruby 开发人员,我正在修改 Chef 食谱。我很好奇是否可以将以下内容放在一行中。

directory "/var/lib/mysql" do
  action :delete
end

我试过这个:

directory "/var/lib/mysql", :action => "delete"

但是,这会引发此错误:

ArgumentError
-------------
wrong number of arguments (3 for 2)

我也见过这个,但这对我来说似乎很尴尬:

directory "/var/lib/mysql" do action => "delete" end
4

2 回答 2

1

you can do two ways, as said using something called a block

directory("/var/lib/mysql") { action :delete }

and you can put your code this way, just to tell you the semi-colon exists in ruby ;))

directory "/var/lib/mysql" do ; action :delete ; end
于 2013-08-20T22:50:00.900 回答
1

大括号等效于do...end,并且更常用于单行:

directory("/var/lib/mysql") { action :delete }

需要添加括号以避免歧义,因为大括号也用于定义散列。

于 2013-08-20T21:25:28.833 回答