Class: Cucumber::Core::Event
- Inherits:
-
Object
- Object
- Cucumber::Core::Event
- Defined in:
- lib/cucumber/core/event.rb
Class Method Summary collapse
-
.event_id ⇒ Object
@return [Symbol] the underscored name of the class to be used as the key in an event registry.
-
.new(*attributes) ⇒ Object
Macro to generate new sub-classes of Event with attribute readers.
Class Method Details
.event_id ⇒ Object
@return [Symbol] the underscored name of the class to be used as the key in an event registry.
45 46 47 |
# File 'lib/cucumber/core/event.rb', line 45 def event_id underscore(self.name.split("::").last).to_sym end |
.new(*attributes) ⇒ Object
Macro to generate new sub-classes of Cucumber::Core::Event with attribute readers.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cucumber/core/event.rb', line 9 def self.new(*attributes) # Use normal constructor for subclasses of Event return super if self.ancestors.index(Event) > 0 Class.new(Event) do attr_reader(*attributes) define_method(:initialize) do |*args| attributes.zip(args) do |name, value| instance_variable_set "@#{name}".to_sym, value end end define_method(:attributes) do attributes.map { |attribute| self.send(attribute) } end define_method(:to_h) do attributes.reduce({}) { |result, attribute| value = self.send(attribute) result[attribute] = value result } end define_method(:event_id) do self.class.event_id end end end |