Created
November 19, 2012 22:12
-
-
Save wkrsz/4114387 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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