Skip to content

Instantly share code, notes, and snippets.

@wkrsz
Created November 19, 2012 22:12
Show Gist options
  • Save wkrsz/4114387 to your computer and use it in GitHub Desktop.
Save wkrsz/4114387 to your computer and use it in GitHub Desktop.
Enumerable.module_eval do
def select_by(attribute_name, value)
detect do |item|
item.send(attribute_name) == value
end
end
def select_by!(attribute_name, value)
select_by(attribute_name, value) \
or raise StandardError.new("can't find item with #{attribute_name} equal to #{value} in #{self.inspect}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment