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:
parent
8a0f6fa97e
commit
437810bff5
2 changed files with 8 additions and 1 deletions
|
@ -56,7 +56,7 @@ class Array #:nodoc:
|
||||||
arr = unless blk
|
arr = unless blk
|
||||||
original_grep(pattern)
|
original_grep(pattern)
|
||||||
else
|
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
|
end
|
||||||
if self.instance_variable_defined?('@__awesome_methods__')
|
if self.instance_variable_defined?('@__awesome_methods__')
|
||||||
arr.instance_variable_set('@__awesome_methods__', self.instance_variable_get('@__awesome_methods__'))
|
arr.instance_variable_set('@__awesome_methods__', self.instance_variable_get('@__awesome_methods__'))
|
||||||
|
|
|
@ -462,6 +462,13 @@ EOS
|
||||||
end
|
end
|
||||||
weird.new.ai(:plain => true).should == ''
|
weird.new.ai(:plain => true).should == ''
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue