diff options
author | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-07-17 00:21:36 -0300 |
---|---|---|
committer | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-07-17 08:56:48 -0300 |
commit | dd5f8bee32757a081a93899acb6189088e1d5305 (patch) | |
tree | 99ef0f0876054eaf21f022e6ac27a8d3d27042c4 /lib | |
parent | a498560c95c80c19ec33e346f45e440612188934 (diff) | |
download | highline-dd5f8bee32757a081a93899acb6189088e1d5305.tar.gz |
It's 'nil check' hunting season
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/highline.rb | 8 | ||||
-rw-r--r-- | lib/highline/color_scheme.rb | 2 | ||||
-rw-r--r-- | lib/highline/import.rb | 4 | ||||
-rw-r--r-- | lib/highline/menu.rb | 14 | ||||
-rwxr-xr-x | lib/highline/question.rb | 18 | ||||
-rw-r--r-- | lib/highline/terminal/jruby_jline.rb | 2 | ||||
-rw-r--r-- | lib/highline/terminal/unix_stty.rb | 2 |
7 files changed, 24 insertions, 26 deletions
diff --git a/lib/highline.rb b/lib/highline.rb index 481e5bd..b0c24ce 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -104,7 +104,7 @@ class HighLine # Returns +true+ if HighLine is currently using a color scheme. def self.using_color_scheme? - not @@color_scheme.nil? + !!@@color_scheme end # Reset HighLine to default. @@ -423,7 +423,7 @@ class HighLine # of the question. # def explain_error(error, question) - say(question.responses[error]) unless error.nil? + say(question.responses[error]) if error say(question.ask_on_error_msg) end @@ -437,7 +437,7 @@ class HighLine # the prompt will not be issued. And we have to account for that now. # Also, JRuby-1.7's ConsoleReader.readLine() needs to be passed the prompt # to handle line editing properly. - say(question) unless ((question.readline) and (question.echo == true and question.limit.nil?)) + say(question) unless ((question.readline) and (question.echo == true and !question.limit)) begin question.get_response_or_default(self) @@ -598,7 +598,7 @@ class HighLine end def get_response_line_mode(question) - if question.echo == true and question.limit.nil? + if question.echo == true and !question.limit get_line(question) else line = "" diff --git a/lib/highline/color_scheme.rb b/lib/highline/color_scheme.rb index 0d07c42..47032f0 100644 --- a/lib/highline/color_scheme.rb +++ b/lib/highline/color_scheme.rb @@ -50,7 +50,7 @@ class HighLine # def initialize( h = nil ) @scheme = Hash.new - load_from_hash(h) unless h.nil? + load_from_hash(h) if h yield self if block_given? end diff --git a/lib/highline/import.rb b/lib/highline/import.rb index 7a0e6fa..ce6ec0e 100644 --- a/lib/highline/import.rb +++ b/lib/highline/import.rb @@ -35,9 +35,9 @@ class Object # def or_ask( *args, &details ) ask(*args) do |question| - question.first_answer = String(self) unless nil? + question.first_answer = String(self) - details.call(question) unless details.nil? + details.call(question) if details end end end diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb index 71c4f47..401cdb7 100644 --- a/lib/highline/menu.rb +++ b/lib/highline/menu.rb @@ -138,7 +138,7 @@ class HighLine def choice( name, help = nil, &action ) @items << [name, action] - @help[name.to_s.downcase] = help unless help.nil? + @help[name.to_s.downcase] = help if help update_responses # rebuild responses based on our settings end @@ -156,7 +156,7 @@ class HighLine def hidden( name, help = nil, &action ) @hidden_items << [name, action] - @help[name.to_s.downcase] = help unless help.nil? + @help[name.to_s.downcase] = help if help end # @@ -305,7 +305,7 @@ class HighLine end # Run or return it. - if not action.nil? + if action @highline = highline_context if @shell result = action.call(name, details) @@ -313,10 +313,8 @@ class HighLine result = action.call(name) end @nil_on_handled ? nil : result - elsif action.nil? - name else - nil + name end ensure # make sure the hidden items are removed, before we return @@ -349,12 +347,12 @@ class HighLine def to_s( ) case @layout when :list - '<%= if header.nil? then '' else "#{header}:\n" end %>' + + %(<%= header ? "#{header}:\n" : '' %>) + "<%= list( menu, #{@flow.inspect}, #{@list_option.inspect} ) %>" + "<%= prompt %>" when :one_line - '<%= if header.nil? then '' else "#{header}: " end %>' + + %(<%= header ? "#{header}: " : '' %>) + "<%= prompt %>" + "(<%= list( menu, #{@flow.inspect}, #{@list_option.inspect} ) %>)" + diff --git a/lib/highline/question.rb b/lib/highline/question.rb index 97b6f65..385924a 100755 --- a/lib/highline/question.rb +++ b/lib/highline/question.rb @@ -334,9 +334,9 @@ class HighLine def expected_range( ) expected = [ ] - expected << "above #{@above}" unless @above.nil? - expected << "below #{@below}" unless @below.nil? - expected << "included in #{@in.inspect}" unless @in.nil? + expected << "above #{@above}" if @above + expected << "below #{@below}" if @below + expected << "included in #{@in.inspect}" if @in case expected.size when 0 then "" @@ -355,7 +355,7 @@ class HighLine # Returns true if _first_answer_ is set. def first_answer?( ) - not @first_answer.nil? + !!@first_answer end # @@ -365,9 +365,9 @@ class HighLine # are not checked. # def in_range? - (@above.nil? or answer > @above) and - (@below.nil? or answer < @below) and - (@in.nil? or @in.include?(answer)) + (!@above or answer > @above) and + (!@below or answer < @below) and + (!@in or @in.include?(answer)) end # @@ -390,7 +390,7 @@ class HighLine # This process is skipped for single character input. # def remove_whitespace( answer_string ) - if @whitespace.nil? + if !@whitespace answer_string elsif [:strip, :chomp].include?(@whitespace) answer_string.send(@whitespace) @@ -442,7 +442,7 @@ class HighLine # and case handling. # def valid_answer? - @validate.nil? or + !@validate or (@validate.is_a?(Regexp) and answer =~ @validate) or (@validate.is_a?(Proc) and @validate[answer]) end diff --git a/lib/highline/terminal/jruby_jline.rb b/lib/highline/terminal/jruby_jline.rb index 8e9a47d..ec7b744 100644 --- a/lib/highline/terminal/jruby_jline.rb +++ b/lib/highline/terminal/jruby_jline.rb @@ -27,7 +27,7 @@ class HighLine statement = highline.render_statement(question) raw_answer = @java_console.readLine(statement, nil) - raise EOFError, "The input stream is exhausted." if raw_answer.nil? and + raise EOFError, "The input stream is exhausted." if !raw_answer and highline.track_eof? end end diff --git a/lib/highline/terminal/unix_stty.rb b/lib/highline/terminal/unix_stty.rb index ba5cc4b..1d9b3d3 100644 --- a/lib/highline/terminal/unix_stty.rb +++ b/lib/highline/terminal/unix_stty.rb @@ -62,7 +62,7 @@ class HighLine raw_answer = readline_read(question_string, question) - if raw_answer.nil? and highline.track_eof? + if !raw_answer and highline.track_eof? raise EOFError, "The input stream is exhausted." end |