From 30d16b0ca408fa1179ba8ab245ea077cbdf6d9ea Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Sat, 14 Jul 2018 18:03:08 +0800 Subject: [PATCH] match? is ruby 2.4+ --- lib/jellyfish/urlmap.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/jellyfish/urlmap.rb b/lib/jellyfish/urlmap.rb index 253d0a4..16c6712 100644 --- a/lib/jellyfish/urlmap.rb +++ b/lib/jellyfish/urlmap.rb @@ -4,7 +4,7 @@ class URLMap def initialize mapped_not_chomped mapped = transform_keys(mapped_not_chomped){ |k| k.sub(%r{/+\z}, '') } keys = mapped.keys - @no_host = !keys.any?{ |k| k.match?(%r{\Ahttps?://}) } + @no_host = !keys.any?{ |k| match?(k, %r{\Ahttps?://}) } string = keys.sort_by{ |k| -k.size }. map{ |k| build_regexp(k) }. @@ -79,5 +79,13 @@ def transform_keys hash, &block end end end + + def match? string, regexp + if string.respond_to?(:match?) + string.match?(regexp) + else + string =~ regexp + end + end end end