Define Instance Variable Outside of Method Defenition (ruby)
- by Ell
Hi all, I am developing (well, trying to at least) a Game framework for the Ruby Gosu library. I have made a basic event system wherebye each Blocks::Event has a list of handlers and when the event is fired the methods are called. At the moment the way to implement an event is as follows:
class TestClass
attr_accessor :on_close
def initialize
@on_close = Blocks::Event.new
end
def close
@on_close.fire(self, Blocks::OnCloseArgs.new)
end
end
But this method of implementing events seems rather long, my question is, how can I make a way so that when one wants an event in a class, they can just do this
class TestClass
event :on_close
def close
@on_close.fire(self, Blocks::OnCloseArgs.new)
end
end
Thanks in advance, ell.