Skip to content

Instantly share code, notes, and snippets.

@mtrudel
Created February 29, 2012 02:58
Show Gist options
  • Save mtrudel/1937223 to your computer and use it in GitHub Desktop.
Save mtrudel/1937223 to your computer and use it in GitHub Desktop.
module Matchers
def add_matcher
[BaseUrlMatcher, YoutubeMatcher].each do |m|
extend m if m.const_get(:Pattern).match @url
end
end
module BaseUrlMatcher
Pattern = //
def summary
"Base #{@url}"
end
end
module YoutubeMatcher
Pattern = /youtube\.com/
def summary
"Youtube #{@url}"
end
end
end
class Visit
include Matchers
def initialize(url)
@url = url
add_matcher
end
end
foo = Visit.new('http://youtube.com')
puts foo.summary #= Youtube matcher
bar = Visit.new('http://cbc.ca')
puts bar.summary #= Base matcher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment