How Does The "#Map(&Proc)" Idiom Work When Introspecting Module Classes

Why design the callback parameter as a Module?

The docs are not super clear, but you can also supply a sub-class of FileWatch. That would let you use locals more easily.

It takes either a module with the needed methods, or a class with the needed methods AND it must be a sub-class of the desired class.

Take a look at the code, specifically, the klass_from_handler method.

Map multidimensional array with join as proc

I don't recommend doing it that way, but if you insist, this is a way to do it:

$, = " "
[["a", "airway", "sarsaparilas"], ["a", "sarsaparilas", "airway"]].map!(&:join)
#=> ["a airway sarsaparilas", "a sarsaparilas airway"]

If necessary, you can revert $, back to the default value after doing this.

$, = nil


Related Topics



Leave a reply



Submit