File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -124,7 +124,11 @@ def ==(other)
124124 def fetch ( name )
125125 attributes . each_key do |attribute_key |
126126 if name . is_a? ( Regexp )
127- return self [ attribute_key ] if name . match? ( attribute_key )
127+ if name . method_exists? :match?
128+ return self [ attribute_key ] if name . match? ( attribute_key )
129+ else
130+ return self [ attribute_key ] if name . match ( attribute_key )
131+ end
128132 elsif canonize_name ( name ) == canonize_name ( attribute_key )
129133 return self [ attribute_key ]
130134 end
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ class AttributesTest < Minitest::Test
2222
2323 it 'fetches regexp attribute' do
2424 assert_equal ( 'Tom' , attributes . fetch ( /givenname/ ) )
25+ assert_equal ( 'Tom' , attributes . fetch ( /gi(.*)/ ) )
26+ assert_nil ( attributes . fetch ( /^z.*/ ) )
2527 assert_equal ( 'Hanks' , attributes . fetch ( /surname/ ) )
2628 end
2729 end
You can’t perform that action at this time.
0 commit comments