Skip to content
Permalink
Browse files

Merge pull request #616 from kachick/implement-enumerable-grep

Implement Enumerable#grep
  • Loading branch information
alex committed Apr 14, 2013
2 parents 0082527 + 5c8b727 commit 8556ee3698b09ea4b46a1e490d09345e0bebf76b
Showing with 18 additions and 3 deletions.
  1. +18 −0 lib-topaz/enumerable.rb
  2. +0 −3 spec/tags/core/enumerable/grep_tags.txt
@@ -419,4 +419,22 @@ def cycle(n = nil, &block)
end
end
end

def grep(pattern, &block)
ret = []
if block
self.each do |elm|
if pattern === elm
ret << yield(elm)
end
end
else
self.each do |elm|
if pattern === elm
ret << elm
end
end
end
ret
end
end
@@ -1,4 +1 @@
fails:Enumerable#grep grep without a block should return an array of all elements === pattern
fails:Enumerable#grep grep with a block should return an array of elements === pattern passed through block
fails:Enumerable#grep grep the enumerable (rubycon legacy)
fails:Enumerable#grep can use $~ in the block when used with a Regexp

0 comments on commit 8556ee3

Please sign in to comment.
You can’t perform that action at this time.