diff options
Diffstat (limited to 'spec/ruby/core/enumerable/grep_spec.rb')
-rw-r--r-- | spec/ruby/core/enumerable/grep_spec.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerable/grep_spec.rb b/spec/ruby/core/enumerable/grep_spec.rb index ac3d3db641..b81075291f 100644 --- a/spec/ruby/core/enumerable/grep_spec.rb +++ b/spec/ruby/core/enumerable/grep_spec.rb @@ -65,6 +65,18 @@ describe "Enumerable#grep" do ["abc", "def"].grep(/b/).should == ["abc"] Regexp.last_match[0].should == "z" end + + it "correctly handles non-string elements" do + 'set last match' =~ /set last (.*)/ + [:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c] + $1.should == 'match' + + o = Object.new + def o.to_str + 'hello' + end + [o].grep(/ll/).first.should.equal?(o) + end end describe "with a block" do |