summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/highline/menu.rb17
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb
index 4db6cd2..42be9bd 100755
--- a/lib/highline/menu.rb
+++ b/lib/highline/menu.rb
@@ -374,12 +374,10 @@ class HighLine
end
def map_items_by_index
- if @index == :letter
- l_index = "`"
- all_items.map { l_index.succ!.dup }
- elsif @index == :capital_letter
- l_index = "@"
- all_items.map { l_index.succ!.dup }
+ if [:letter, :capital_letter].include?(@index)
+ # @ and ` are the previous ASCII characters to A and a respectively
+ prev_char = (@index == :capital_letter ? '@' : '`')
+ all_items.map { prev_char.succ!.dup }
else
(1..all_items.size).map(&:to_s)
end
@@ -520,10 +518,9 @@ class HighLine
case @index
when :number
["#{ix + 1}#{@index_suffix}", text]
- when :letter
- ["#{('a'.ord + ix).chr}#{@index_suffix}", text]
- when :capital_letter
- ["#{('A'.ord + ix).chr}#{@index_suffix}", text]
+ when :letter, :capital_letter
+ first_letter = (@index == :capital_letter ? 'A' : 'a')
+ ["#{(first_letter.ord + ix).chr}#{@index_suffix}", text]
when :none
[text, ""]
else