这个ruby函数做什么?
我是ruby的新手,我正在尝试解决puppet给我的一个错误。到目前为止,谷歌还没有帮助我进一步了解这个问题。附加的 当puppet启动redis init脚本时,它返回以下错误:这个ruby函数做什么?,ruby,puppet,Ruby,Puppet,我是ruby的新手,我正在尝试解决puppet给我的一个错误。到目前为止,谷歌还没有帮助我进一步了解这个问题。附加的 当puppet启动redis init脚本时,它返回以下错误: Debug: Executing '/etc/init.d/redis_6390 start' Error: Could not start Service[redis_6390]: Execution of '/etc/init.d/redis_6390 start' returned 1: Error: Coul
Debug: Executing '/etc/init.d/redis_6390 start'
Error: Could not start Service[redis_6390]: Execution of '/etc/init.d/redis_6390 start' returned 1: Error: Could not execute posix command: Exec format error - /etc/init.d/redis_6390
Wrapped exception:
Execution of '/etc/init.d/redis_6390 start' returned 1: Error: Could not execute posix command: Exec format error - /etc/init.d/redis_6390
Error: /Stage[main]/Ac_redis_6390/Service[redis_6390]/ensure: change from stopped to running failed: Could not start Service[redis_6390]: Execution of '/etc/init.d/redis_6390 start' returned 1: Error: Could not execute posix command: Exec format error - /etc/init.d/redis_6390
Debug: Class[Ac_redis_6390]: The container Stage[main] will propagate my refresh event
我发现puppet源代码中有一行“无法执行posix命令”
这些线是干什么的?我试图理解是什么引发了这个异常
options[:custom_environment] ||= {}
Puppet::Util.withenv(options[:custom_environment]) do
Kernel.exec(*command)
end
options[:custom_-environment]|={}
表示“如果options[:custom_-environment]为nil
或false
,则分配{}”
并执行系统命令命令
命令
是一个数组
,它的第一个值是命令本身,数组的其他值是系统命令的参数
我希望它能有所帮助。我将假设两个容易混淆的部分是
|
和*命令
| |=
是一个条件赋值运算符,仅当其左侧的变量计算结果为false
时才执行赋值,通常是在nil
或false
时。这通常与实例变量或散列成员一起使用,它们在未设置时的计算结果都为零
*
是一个splat运算符,用于将数组转换为传递到方法中的一系列参数。以下示例是相同的:
# Pass colors directly to use_colors.
use_colors('red', 'green', 'blue')
# Unpack an Array into an argument list for use_colors.
colors = ['red', 'green', 'blue']
use_colors(*colors)
同样,您可以在方法声明中使用splat运算符,以数组形式接收其余传递的参数:
# This method can accept any number of colors, including zero.
def use_colors(*colors)
colors.each do |color|
puts "Using color: #{color}!"
end
end
# This method can accept any number of colors, including zero.
def use_colors(*colors)
colors.each do |color|
puts "Using color: #{color}!"
end
end