Skip to content

Instantly share code, notes, and snippets.

@abrongersma
Created April 25, 2013 00:34
Show Gist options
  • Select an option

  • Save abrongersma/5456696 to your computer and use it in GitHub Desktop.

Select an option

Save abrongersma/5456696 to your computer and use it in GitHub Desktop.
class Array
def new_count(&proc)
if proc
self.select(&proc).length
else
self.length
end
end
end
## Tim
class Array
def new_count
count = 0
0.upto(self.length - 1) do |index|
count += 1 if (yield self[index])
end
count
end
end
#Ryan
class Array
def new_count(&block)
if block
self.select(&block).length
else
self.length
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment