[Groonga-commit] droonga/drntest at ddc500f [master] Use "case when"

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Apr 15 12:13:35 JST 2015


Kouhei Sutou	2015-04-15 12:13:35 +0900 (Wed, 15 Apr 2015)

  New Revision: ddc500fbfd64a4f2de09f4db5ca957c83719feaa
  https://github.com/droonga/drntest/commit/ddc500fbfd64a4f2de09f4db5ca957c83719feaa

  Message:
    Use "case when"
    
    "case XXX when ..." is more readable rather than "if XXX ... elsif XXX
    ..."  because condition target ("XXX" in this case) is clear.

  Modified files:
    lib/drntest/directive.rb

  Modified: lib/drntest/directive.rb (+6 -5)
===================================================================
--- lib/drntest/directive.rb    2015-04-14 20:50:04 +0900 (cb34233)
+++ lib/drntest/directive.rb    2015-04-15 12:13:35 +0900 (7cf2fe9)
@@ -1,4 +1,4 @@
-# Copyright (C) 2013  Droonga Project
+# Copyright (C) 2013-2015  Droonga Project
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -81,13 +81,14 @@ module Drntest
       @timeout_seconds = nil
 
       parameters.each do |parameter|
-        if parameter =~ /\A(\d+)(?:messages|msg)?\z/
+        case parameter
+        when /\A(\d+)(?:messages|msg)?\z/
           @max_messages = $1.to_i
-        elsif parameter =~ /\A(\d+\.?|\.\d+|\d+\.\d+)s(?:ec(?:onds?)?)?\z/
+        when /\A(\d+\.?|\.\d+|\d+\.\d+)s(?:ec(?:onds?)?)?\z/
           @timeout_seconds = $1.to_f
-        elsif parameter =~ /\A(\d+\.?|\.\d+|\d+\.\d+)m(?:inutes?)?\z/
+        when /\A(\d+\.?|\.\d+|\d+\.\d+)m(?:inutes?)?\z/
           @timeout_seconds = $1.to_f * ONE_MINUTE_IN_SECONDS
-        elsif parameter =~ /\A(\d+\.?|\.\d+|\d+\.\d+)h(?:ours?)?\z/
+        when /\A(\d+\.?|\.\d+|\d+\.\d+)h(?:ours?)?\z/
           @timeout_seconds = $1.to_f * ONE_HOUR_IN_SECONDS
         end
       end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index