Created
February 29, 2012 02:58
-
-
Save mtrudel/1937223 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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