Skip to content

Instantly share code, notes, and snippets.

@ZempTime
Created October 24, 2013 21:12
Show Gist options
  • Save ZempTime/7145075 to your computer and use it in GitHub Desktop.
Save ZempTime/7145075 to your computer and use it in GitHub Desktop.
require 'byebug'
lambda {
setups = []
events = {}
Kernel.send :define_method, :event do |name, &block|
events[name] = block
end
Kernel.send :define_method, :setup do |&block|
setups << block
end
Kernel.send :define_method, :each_event do |&block|
events.each_pair do |name, event|
block.call name, event
end
end
Kernel.send :define_method, :each_setup do |&block|
setups.each do |setup|
block.call setup
end
end
}.call
byebug # This line blows up
Dir.glob('*events.rb').each do |file|
load file
each_event do |name, event|
env = Object.new
each_setup do |setup|
env.instance_eval(&setup)
end
puts "ALERT: #{name}" if env.instance_eval(&event)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment