Pregunta

Refers to - bizzare way of calling Procs?

@BroiSatse thanks a lot for the answer. One additional moment to clarify - what if one needs to pass extra arguments (added to the code as param_1 and _2):

def callbacks(param_1, param_2, procs)
  procs[:var_1].call(param_1)
  puts "Proceed"
  procs[:var_2].call(param_2)
end

callbacks(arg_1, arg_2, :var_1 => Proc.new {block_1},
         :var_2 => Proc.new {block_2})

What goes first? i.e. what will be passed first to execute the def callbacks- arguments (arg_1, arg_2) in place of params (param_1, param_2) or procs (:var_1, :var_2)? This is important to know to properly code the params line - def callbacks(param_1, param_2, procs).

Thanks in advance for any help.

¿Fue útil?

Solución

I can't see how you think this will possibly make a difference here, but the arguments are evaluated from left to right and in YARV are pushed onto the stack in that order. Obviously, though, they are all passed before the called method starts executing.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top