overdawn
overdawn

Reputation: 391

Why design the callback parameter as a Module?

According to the documentation for EventMachine.watch_file the handler argument has to be a Module (or a class inheriting from EventMachine::FileWatch). Why is it designed this way? For me a block (or Proc) argument would be more natural and flexible (since it allows to use local variables via closure)...

Upvotes: 1

Views: 32

Answers (1)

Nick Veys
Nick Veys

Reputation: 23949

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.

Upvotes: 1

Related Questions