0
昨日私はすでに "no implicit conversion of Symbol into Integer, Ruby"であなたに尋ねました。あなたはその質問に答えるためにさらに詳しい情報が必要だと思います。それが私が再び尋ねた理由です。私はシステムをruby 1.8.7から新しいバージョンのruby 2.3.1p112にアップデートしました。私は3コメント場合Ruby、シンボルの整数への暗黙的変換なし
def element_switch_wago_do(step)
raise Rutema::ParserError, "Missing DO tag!" unless step.has_do?
raise Rutema::ParserError, "Missing DO value!" unless step.has_value?
raise Rutema::ParserError, "Used DO value '#{step.value}' not supported [0||1 valid]!" unless ((0 == step.value.to_i) || (step.value.to_i == 1))
step.txt="Switch Wago DIGITAL output-pin #{step.do} to #{step.value}"
ip = "{WAGO_IP}"
port = "{WAGO_PORT}"
step.cmd = Litu::RubyCommand.new("switch_wago_do") do |cmd, context|
Litu::subst_template!(ip, context)
Litu::subst_template!(port, context)
Litu::subst_template!(step.do, context)
ModBus::TCPClient.new(ip, port.to_i) do |cl|
cl.with_slave(1) do |slave|
slave.debug = false
slave.write_single_coil(step.do.to_i,step.value.to_i) end
end
end
end
class RubyCommand
include Patir::Command
attr_reader :cmd,:working_directory,:killProc
def initialize params,&block
@killProc=params[:killProc]
@name=params[:name]
@working_directory=params[:working_directory]||"."
if block_given?
@cmd=block
else
raise "You need to provide a block"
end
end
#Runs the associated block
def run context=nil
@run=true
begin
t1=Time.now
cmd = @cmd
pwd = @working_directory
p = Dir.pwd
puts "######: #{cmd}:"
Litu::subst_template!(pwd, context)
puts "before block in dir #{Dir.pwd}"
Dir.chdir(pwd) do
p = Dir.pwd
puts "in block in dir #{cmd}"
@cmd.call(self, context)
@status=:success
end
puts ":###### #{p}"
rescue StandardError
error << "\n#{$!.message}"
error << "\n#{$!.backtrace}" if $DEBUG
@status=:error
ensure
@exec_time=Time.now-t1
end
return @status
end
def kill!
@killProc.call if @killProc
end
def to_s
return @name
end
end
:
は、私がテストを実行したい場合は、私は常にエラーを取得:FATAL:コードここ
整数へのシンボルの無暗黙的な変換がありますRubyCommand内の行、私はエラーが表示されません。
#@killProc=params[:killProc]
#@name=params[:name]
#@working_directory=params[:working_directory]||"."
問題は配列とハッシュで発生します。しかし、私はどのようにこのコードを稼働させるのか分かりません。
どのように 'RubyCommand'インスタンスを作成しますか? – Aleksey
新しい質問を作成する代わりに、元の質問をよく修正してください。 (一方、もう一方の質問は重複としてマークされています)。 – knut
in element_Switch_wago_do私はこのようなインスタンスを作成します:RubyCommand.new( "switch_wago_do")do | cmd、context | RubyCommandは同じスクリプトで定義されたクラスです – shube