Module: RGL::GraphVisitor::ClassMethods

Included in:
RGL::GraphVisitor
Defined in:
lib/rgl/graph_visitor.rb

Overview

module DistanceMapSupport

Instance Method Summary collapse

Instance Method Details

#def_event_handlers(*events) ⇒ Object Also known as: def_event_handler

Defines an event handler.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rgl/graph_visitor.rb', line 102

def def_event_handlers(*events)
  events.each do |event|
    params = event.to_s.include?('edge') ? 'u, v' : 'u'

    handler = "@#{event}_event_handler"

    class_eval <<-END
      def handle_#{event}(#{params})
        #{handler}.call(#{params}) if defined? #{handler}
      end

      def set_#{event}_event_handler(&block)
        #{handler} = block
      end
    END
  end
end