
Hi! If you run the gen_proc function, then the variables secret1 and secret2 are regenerated again and their values are changed but if you do "my_proc = gen_proc", then my_proc is the following code { puts secret1 * secret2 nil } .... In this case the variables secret1 and secret2 do NOT change and every time you execute the "my_proc" procedure (which is different from the gen_proc function) it always displays the same result on the screen. :-) Enviado con el correo electrónico seguro de Proton Mail. ------- Original Message ------- El jueves, 11 de mayo de 2023 a las 12:12, hmdne via ruby-talk <ruby-talk@ml.ruby-lang.org> escribió:
If there's an interest in such posts, I will write more. The idea is that I will provide examples of lesser-known features of Ruby. Later on, I will do a longer write-up where I will provide a solution and explain it unless someone will do it before me :)
Let's say I have a program I can't modify:
`ruby def gen_proc secret1 = rand secret2 = rand proc do p secret1 * secret2 nil end end my_proc = gen_proc binding.irb`
It will launch an interactive Ruby console. When I type:
`ruby my_proc.() # .() is a shortcut of .call()`
It will print some number, but each time I will type this expression, it will be the same number (until I relaunch the console). This number is derived from `secret1` and `secret2` variables. Those variables are stored somewhere - but where? What is the best way for me to obtain values of those variables? Do note that I can't modify the code :) ______________________________________________ ruby-talk mailing list -- ruby-talk@ml.ruby-lang.org To unsubscribe send an email to ruby-talk-leave@ml.ruby-lang.org ruby-talk info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-talk.ml.ruby-lang.org...