class Cucumber::Core::Event
def self.new(*events)
Macro to generate new sub-classes of {Event} with
def self.new(*events) # Use normal constructor for subclasses of Event return super if ancestors.index(Event) > 0 Class.new(Event) do # NB: We need to use metaprogramming here instead of direct variable obtainment # because JRuby does not guarantee the order in which variables are defined is equivalent # to the order in which they are obtainable # # See https://github.com/jruby/jruby/issues/7988 for more info attr_reader(*events) define_method(:initialize) do |*attributes| events.zip(attributes) do |name, value| instance_variable_set(:"@#{name}", value) end end define_method(:attributes) do events.map { |var| instance_variable_get(:"@#{var}") } end define_method(:to_h) do events.zip(attributes).to_h end def event_id self.class.event_id end end end