Class: Event
- Inherits:
-
Object
- Object
- Event
- Defined in:
- lib/universum/universum.rb
Overview
base class for events
Class Method Summary collapse
-
.build_class(*fields) ⇒ Object
(also: new)
return a new Struct-like read-only class.
Class Method Details
.build_class(*fields) ⇒ Object Also known as: new
return a new Struct-like read-only class
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/universum/universum.rb', line 426 def self.build_class( *fields ) klass = Class.new( Event ) do define_method( :initialize ) do |*args| fields.zip( args ).each do |field, arg| instance_variable_set( "@#{field}", arg ) end end fields.each do |field| define_method( field ) do instance_variable_get( "@#{field}" ) end end end ## add self.new too - note: call/forward to "old" orginal self.new of Event (base) class klass.define_singleton_method( :new ) do |*args| old_new( *args ) end klass end |