My subject is probably not the best description, so here is an example
of what I am trying to do.
class ExampleController < ApplicationController
@name = ‘John’
event(:event, :context) do
@name << ’ Doe’
# Retrieve the module based on the parameters.
# Call EventManager::Event::Context.before if it exists with
access to the variables from where event was called.
yield if block_given?
# Call EventManager::Event::Context.after if it exists with access
to the variables from where event was called.
puts “Hi John” if @name == ‘John’
def after puts "Who?" if @name != 'John' end end
Basically I want to be able to store methods in nested modules for
separation, but be able to call them dynamically within controller
actions via the event method.
My current solutions involves module_function for all the before and
after methods and retrieving controller information by passing the
controller to each action and using send and instance_variable_get/set
which is less than ideal in my opinion.
Any suggestions, or hints?