我是新来的红宝石,我正在写一个傀儡模块,通过工头访问。从数组创建参数?
我写它由福尔曼的智能类参数使用,所以它可以从福尔曼的Web控制台配置。
我想知道如何为一个设备可能具有的48个可能的端口创建一个参数。而不是手动输入端口,我想知道是否可以动态执行此操作。
例如,而不是这样的:
class ciscobaseconfig (
$interface_description_lan = 'A LAN interface'
) {
interface {
'FastEthernet 0/1':
description => $interface_description_lan
}
interface {
'FastEthernet 0/2':
description => $interface_description_lan
}
}
我想这样做:
class ciscobaseconfig (
$interface_description_lan = 'A LAN interface',
) {
interface {
(0..48).each do |i|
"FastEthernet 0/#{i}":
description => $interface_description_lan
end
}
}
继评论者的建议,我想这一点,但它不能正常工作:
class ciscobaseconfig (
$interface_description_lan = 'A LAN interface',
) {
arrInterfaces = Array(1..48)
arrInterfaces.each{
interface {
|intNum| puts "FastEthernet 0/#{intNum}":
description => $interface_description_lan
}
}
}
== >> arr = Array(1..10)= then => arr.each {| x |把“wadupp#{x}”} – zee
与我在做的事情不一样吗?一个完整的例子是什么样的? – red888
删除了[ruby]标签,因为它比这个问题的相关性更混乱。 –