lib/tty/prompt/choices.rb in tty-prompt-0.4.0 vs lib/tty/prompt/choices.rb in tty-prompt-0.5.0
- old
+ new
@@ -83,10 +83,26 @@
#
# @return [Choice]
#
# @api public
def pluck(name)
- find { |choice| choice.name == name }
+ map { |choice| choice.public_send(name) }
+ end
+
+ # Find a matching choice
+ #
+ # @exmaple
+ # choices.find_by(:name, 'small')
+ #
+ # @param [Symbol] attr
+ # the attribute name
+ # @param [Object] value
+ #
+ # @return [Choice]
+ #
+ # @api public
+ def find_by(attr, value)
+ find { |choice| choice.public_send(attr) == value }
end
end # Choices
end # Prompt
end # TTY