1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Fixed array grep for patters with / character

This commit is contained in:
Mike Dvorkin 2011-05-06 14:49:51 -07:00
parent 8a0f6fa97e
commit 437810bff5
2 changed files with 8 additions and 1 deletions

View file

@ -56,7 +56,7 @@ class Array #:nodoc:
arr = unless blk
original_grep(pattern)
else
original_grep(pattern) { |match| eval("%Q/#{match}/ =~ #{pattern.inspect}", blk.binding); yield match }
original_grep(pattern) { |match| eval("%Q/#{match.to_s.gsub('/', '\/')}/ =~ #{pattern.inspect}", blk.binding); yield match }
end
if self.instance_variable_defined?('@__awesome_methods__')
arr.instance_variable_set('@__awesome_methods__', self.instance_variable_get('@__awesome_methods__'))

View file

@ -462,6 +462,13 @@ EOS
end
weird.new.ai(:plain => true).should == ''
end
# See https://github.com/michaeldv/awesome_print/issues/35
it "handle array grep when pattern contains / chapacter" do
hash = { "1/x" => 1, "2//x" => :"2" }
grepped = hash.keys.grep(/^(\d+)\//) { $1 }
grepped.ai(:plain => true, :multiline => false).should == '[ "1", "2" ]'
end
end
#------------------------------------------------------------------------------