ruby - How do I give one method invoked in a block the ability to see variables set in the context of the calling function? -


I have a module that defines a method, log , which results in a The prefix will add a different method, : :

  Module M DF log (and block) str = "log in:" block.call say end def ( Value) + value and end   

I want to be able to use M inside a class block, such as :

  Expand square C extension M (say "one" "two"} End   

and get:

  # = & gt; "Login: one" # = & gt; "log in: two"   

Essentially, I should be able to reach values ​​in the log in logs which only call logging Consequently, I like to avoid example variables, global variables, et.

What is the correct way to turn it off?

One way to do this is: -

  Module M def log (and R block) str = "log:" block.call (str) say enddef (str, value) extends str + value end end class c {{s | | Say, "one", "two"} end    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -