Skip to content

Instantly share code, notes, and snippets.

@kek
Last active December 20, 2015 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kek/6192831 to your computer and use it in GitHub Desktop.
Save kek/6192831 to your computer and use it in GitHub Desktop.
def rule message, &block
@rules ||= []
@rules << Class.new {
attr_reader :message
def initialize(message, &block)
@message = message
@block = block
end
def matches?
@block.call
end
}.new(message, &block)
end
def rule message, &block
@rules << Class.new {
define_method(:message) { message }
define_method(:matches?) { block.call }
}.new
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment