Skip to content

Instantly share code, notes, and snippets.

@perspectivezoom
Created June 15, 2012 19:55
Show Gist options
  • Select an option

  • Save perspectivezoom/2938427 to your computer and use it in GitHub Desktop.

Select an option

Save perspectivezoom/2938427 to your computer and use it in GitHub Desktop.
class Array
def new_count
self.inject(0) { |accum , i| yield(i) ? accum += 1 : accum }
end
end
# Exercise for the reader: Figure out why my original idea: "self.inject(0) { |accum , i| accum += 1 if yield(i) }" is not completely valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment