[前][次][番号順一覧][スレッド一覧]

ruby-changes:50787

From: nobu <ko1@a...>
Date: Wed, 28 Mar 2018 19:23:01 +0900 (JST)
Subject: [ruby-changes:50787] nobu:r62993 (trunk): Use Regexp#match? in time.rb for conditionals

nobu	2018-03-28 19:22:57 +0900 (Wed, 28 Mar 2018)

  New Revision: 62993

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62993

  Log:
    Use Regexp#match? in time.rb for conditionals
    [Fix GH-1852]
    
    From: Bart <bartdewater@g...>

  Modified files:
    trunk/lib/time.rb
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 62992)
+++ lib/time.rb	(revision 62993)
@@ -136,7 +136,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L136
       zone = zone.upcase
       if /\A([+-])(\d\d)(:?)(\d\d)(?:\3(\d\d))?\z/ =~ zone
         off = ($1 == '-' ? -1 : 1) * (($2.to_i * 60 + $4.to_i) * 60 + $5.to_i)
-      elsif /\A[+-]\d\d\z/ =~ zone
+      elsif zone.match?(/\A[+-]\d\d\z/)
         off = zone.to_i * 3600
       elsif ZoneOffset.include?(zone)
         off = ZoneOffset[zone] * 3600
@@ -168,11 +168,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L168
       #   They are not appropriate for specific time zone such as
       #   Europe/London because time zone neutral,
       #   So -00:00 and -0000 are treated as UTC.
-      if /\A(?:-00:00|-0000|-00|UTC|Z|UT)\z/i =~ zone
-        true
-      else
-        false
-      end
+      zone.match?(/\A(?:-00:00|-0000|-00|UTC|Z|UT)\z/i)
     end
     private :zone_utc?
 
@@ -521,14 +517,14 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L517
     # You must require 'time' to use this method.
     #
     def httpdate(date)
-      if /\A\s*
+      if date.match?(/\A\s*
           (?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\x20
           (\d{2})\x20
           (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\x20
           (\d{4})\x20
           (\d{2}):(\d{2}):(\d{2})\x20
           GMT
-          \s*\z/ix =~ date
+          \s*\z/ix)
         self.rfc2822(date).utc
       elsif /\A\s*
              (?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),\x20

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]