summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatrinox <geofflee21@me.com>2016-02-01 21:41:58 -0800
committerAbinoam Praxedes Marques Jr <abinoam@gmail.com>2016-02-19 04:15:08 -0300
commit3f1935e62b1b8e6f45d02895956c7d6085da9820 (patch)
treee98ee38b6bfb0b2178e073cd44fa7ffbedf85c33
parent4bb4b94439ecc41169cf5569709f8c78a37cd33e (diff)
downloadhighline-3f1935e62b1b8e6f45d02895956c7d6085da9820.tar.gz
Change name keyword arg to first positional arg because it's required
-rw-r--r--lib/highline/menu.rb25
-rw-r--r--test/test_menu.rb8
2 files changed, 14 insertions, 19 deletions
diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb
index aae0fc0..9318a6f 100644
--- a/lib/highline/menu.rb
+++ b/lib/highline/menu.rb
@@ -161,12 +161,8 @@ class HighLine
# menu.help("rules", "The rules of this system are as follows...")
# end
- 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
+ def choice( name, help = nil, text = nil, &action )
+ item = MenuItem.new(name, text: text, help: help, action: action)
@items << item
@help.merge!(item.item_help)
update_responses # rebuild responses based on our settings
@@ -209,7 +205,7 @@ class HighLine
# @return (see #choice)
def hidden( name, help = nil, &action )
- item = MenuItem.new(name: name, text: name, help: help, action: action)
+ item = MenuItem.new(name, text: name, help: help, action: action)
@hidden_items << item
@help.merge!(item.item_help)
end
@@ -496,15 +492,14 @@ class HighLine
attr_reader :name, :text, :help, :action
#
- # @param text: The text that displays for that choice (defaults to name)
- # @param name: The name that is matched against the user input
- # @param help: help, see above (not sure how it works)
- # @param action: a block that gets called when choice is selected
+ # @param name [String] The name that is matched against the user input
+ # @param text: [String] The text that displays for that choice (defaults to name)
+ # @param help: [String] help, see above (not sure how it works)
+ # @param action: [Block] a block that gets called when choice is selected
#
- def initialize(attributes)
- attributes[:text] ||= attributes[:name]
- @name = attributes[:name]
- @text = attributes[:text]
+ def initialize(name, attributes)
+ @name = name
+ @text = attributes[:text] || @name
@help = attributes[:help]
@action = attributes[:action]
end
diff --git a/test/test_menu.rb b/test/test_menu.rb
index 058c1ba..777b977 100644
--- a/test/test_menu.rb
+++ b/test/test_menu.rb
@@ -118,8 +118,8 @@ class TestMenu < Minitest::Test
@input.rewind
selected = @terminal.choose do |menu|
- menu.add_item(HighLine::Menu::MenuItem.new(name: "Sample1", text: "Sample2"))
- menu.add_item(HighLine::Menu::MenuItem.new(name: "Sample2", text: "Sample1"))
+ menu.add_item(HighLine::Menu::MenuItem.new("Sample1", text: "Sample2"))
+ menu.add_item(HighLine::Menu::MenuItem.new("Sample2", text: "Sample1"))
end
assert_equal(selected, "Sample1")
assert_equal("1. Sample2\n" +
@@ -132,8 +132,8 @@ class TestMenu < Minitest::Test
@input.rewind
selected = @terminal.choose do |menu|
- menu.add_item(HighLine::Menu::MenuItem.new(name: "Sample1", text: "Sample2"))
- menu.add_item(HighLine::Menu::MenuItem.new(name: "Sample2", text: "Sample1"))
+ menu.add_item(HighLine::Menu::MenuItem.new("Sample1", text: "Sample2"))
+ menu.add_item(HighLine::Menu::MenuItem.new("Sample2", text: "Sample1"))
end
assert_equal(selected, "Sample2")
assert_equal("1. Sample2\n" +