proc question

J

Jessica Colnago

Hi there,

I'm trying to create a parser that creates a statemachine, using the
statemachine gem, from a scxml file. But I got stuck when I started
dealing with proc.
I can't understand why it works when I do this:

action = @actions.last
procedure = proc {@@logger.puts action if (action and @@logger)}

But not work when I do this:

action = @actions
procedure = proc {
action.each do |a|
case a[0]
when 'log'
@@logger.puts a[1]
when 'send'
@@queue.send(a[1], a[2])
end
end
}

(at first I was only dealing with one possibility ('log') and now I'm
trying to make it able to treat multiple possibilities.)

I then use 'procedure' as a parameter here:

if (@transitions.last.target != nil) # if it has a target state
@state.last.event(@transitions.last.event.to_sym,
@transitions.last.target.to_sym, procedure)
else # it is its own target state
@state.last.event(@transitions.last.event.to_sym,
@state.last.id.to_sym, procedure)
end

Best regards,
Jessica
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top