diff --git a/lib/tzinfo/timezone.rb b/lib/tzinfo/timezone.rb index 8d1d1457..bdb4fb4d 100644 --- a/lib/tzinfo/timezone.rb +++ b/lib/tzinfo/timezone.rb @@ -1119,6 +1119,14 @@ def hash identifier.hash end + # @param regex [Regex] a `Regex` to match against the identifier of this + # {Timezone}. + # @return [Integer, nil] `Integer` offset of the match on the identifier, + # otherwise `nil` if there is no match. + def =~(regex) + regex =~ identifier + end + # Returns a serialized representation of this {Timezone}. This method is # called when using `Marshal.dump` with an instance of {Timezone}. # diff --git a/test/tc_timezone.rb b/test/tc_timezone.rb index d091a77e..8e503085 100644 --- a/test/tc_timezone.rb +++ b/test/tc_timezone.rb @@ -1700,6 +1700,12 @@ def test_hash assert_equal('America/New_York'.hash, TestTimezone.new('America/New_York').hash) end + define_method("test_=~_operator_matches_against_identifier") do + tz = TestTimezone.new('Europe/London') + assert_equal(0, tz =~ /Europe\/London/) + assert_nil(tz =~ /America\/NewYork/) + end + def test_marshal_data tz = Timezone.get('Europe/London') marshalled_tz = Marshal.load(Marshal.dump(tz))