Some more idiomatic Ruby code.

This commit is contained in:
Renato Silva 2014-12-02 21:40:41 -02:00
parent 5f234f88e8
commit 74223b62d7
2 changed files with 20 additions and 18 deletions

View File

@ -1,2 +1,5 @@
Style/IndentationWidth: Style/IndentationWidth:
Width: 4 Width: 4
Metrics/LineLength:
Max: 160

View File

@ -122,7 +122,7 @@ module EasyOptions
doc = doc.find_all do |line| doc = doc.find_all do |line|
line =~ /^##[^#]*/ line =~ /^##[^#]*/
end end
doc = doc.map do |line| doc.map do |line|
line.strip! line.strip!
line.sub!(/^## ?/, '') line.sub!(/^## ?/, '')
line.gsub!(/@script.name/, File.basename($PROGRAM_NAME)) line.gsub!(/@script.name/, File.basename($PROGRAM_NAME))
@ -202,14 +202,14 @@ module EasyOptions
else else
puts @documentation puts @documentation
end end
exit -1 exit(-1)
end end
# Regular arguments # Regular arguments
next_is_value = false next_is_value = false
raw_arguments.each do |argument| raw_arguments.each do |argument|
if argument.start_with?('-') if argument.start_with?('-')
known_option = @known_options.find { |known_option| known_option.in?(argument) } known_option = @known_options.find { |option| option.in?(argument) }
next_is_value = (known_option && !known_option.boolean) next_is_value = (known_option && !known_option.boolean)
else else
arguments << argument unless next_is_value arguments << argument unless next_is_value
@ -218,7 +218,7 @@ module EasyOptions
end end
# Bash support # Bash support
if BashOutput return unless BashOutput
@options.keys.each do |name| @options.keys.each do |name|
puts "#{name}=\"#{@options[name].to_s.sub('true', 'yes')}\"" puts "#{name}=\"#{@options[name].to_s.sub('true', 'yes')}\""
end end
@ -227,7 +227,6 @@ module EasyOptions
puts "arguments+=(\"#{argument}\")" puts "arguments+=(\"#{argument}\")"
end end
end end
end
def self.finish(error) def self.finish(error)
$stderr.puts "Error: #{error}." $stderr.puts "Error: #{error}."