summaryrefslogtreecommitdiff
path: root/lib/highline/menu.rb
diff options
context:
space:
mode:
authormatrinox <geofflee21@me.com>2016-01-25 21:34:32 -0800
committerAbinoam Praxedes Marques Jr <abinoam@gmail.com>2016-02-19 03:57:18 -0300
commit499f393ec533239f1457a77d2004fab6d454fe10 (patch)
tree8746ef69473731d5dfc55edbc54796a266efed90 /lib/highline/menu.rb
parent8957d31c0407fe1b1b32c442dbe8217a026a3427 (diff)
downloadhighline-499f393ec533239f1457a77d2004fab6d454fe10.tar.gz
Remove keyword args to preserve backwards compatability (and ruby 1.9 support)
Allow passing in HighLine::Menu::MenuItem directly. Menu choice can be either name or the MenuItem.
Diffstat (limited to 'lib/highline/menu.rb')
-rw-r--r--lib/highline/menu.rb22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb
index 5d5e6b5..e953f0e 100644
--- a/lib/highline/menu.rb
+++ b/lib/highline/menu.rb
@@ -161,8 +161,12 @@ class HighLine
# menu.help("rules", "The rules of this system are as follows...")
# end
- def choice( name, text: nil, help: nil, &action )
- item = MenuItem.new(name: name, text: text, help: help, action: action)
+ def choice( name_or_item, help = nil, &action )
+ if name_or_item.is_a?(MenuItem)
+ item = name_or_item
+ else
+ item = MenuItem.new(name: name_or_item, text: name_or_item, help: help, action: action)
+ end
@items << item
@help.merge!(item.item_help)
update_responses # rebuild responses based on our settings
@@ -237,7 +241,7 @@ class HighLine
"a specific topic enter:\n\thelp [TOPIC]\nTry asking " +
"for help on any of the following:\n\n" +
"<%= list(#{topics.inspect}, :columns_across) %>"
- choice(:help, help: help_help) do |command, topic|
+ choice(:help, help_help) do |command, topic|
topic.strip!
topic.downcase!
if topic.empty?
@@ -485,12 +489,12 @@ class HighLine
# @param help: help, see above (not sure how it works)
# @param action: a block that gets called when choice is selected
#
- def initialize(name:, text: nil, help: nil, action: nil)
- text ||= name
- @name = name
- @text = text
- @help = help
- @action = action
+ def initialize(attributes)
+ attributes[:text] ||= attributes[:name]
+ @name = attributes[:name]
+ @text = attributes[:text]
+ @help = attributes[:help]
+ @action = attributes[:action]
end
def item_help