Skip to content

Instantly share code, notes, and snippets.

@mvr
Created November 11, 2009 11:11
Show Gist options
  • Save mvr/231868 to your computer and use it in GitHub Desktop.
Save mvr/231868 to your computer and use it in GitHub Desktop.
# YARR!
class Event
def self.[](*attributes)
c = Class.new(Event)
unless attributes.empty?
attributes.each do |attribute|
c.send(:attr_accessor, attribute)
end
c.class_eval <<-END
def initialize(#{attributes.join(", ")})
#{attributes.map { |attr| "@#{attr}=#{attr}" }.join(";") }
end
END
end
c
end
end
class Test < Event[:this, :that]; end
a = Test.new(3, 4)
a.this = 5
p a.this
p a.that
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment