Project

General

Profile

Feature #10177 ยป Replace_Hash#has_something.PATCH

gogotanaka (Kazuki Tanaka), 08/27/2014 10:55 PM

View differences:

lib/cgi/cookie.rb
74 74
      end
75 75

  
76 76
      options = name
77
      unless options.has_key?("name")
77
      unless options.key?("name")
78 78
        raise ArgumentError, "`name' required"
79 79
      end
80 80

  
......
150 150
        name = CGI.unescape(name)
151 151
        values ||= ""
152 152
        values = values.split('&').collect{|v| CGI.unescape(v,@@accept_charset) }
153
        if cookies.has_key?(name)
153
        if cookies.key?(name)
154 154
          values = cookies[name].value + values
155 155
        end
156 156
        cookies[name] = Cookie.new(name, *values)
lib/cgi/core.rb
154 154
      content_type = options
155 155
      buf = _header_for_string(content_type)
156 156
    elsif options.is_a?(Hash)
157
      if options.size == 1 && options.has_key?('type')
157
      if options.size == 1 && options.key?('type')
158 158
        content_type = options['type']
159 159
        buf = _header_for_string(content_type)
160 160
      else
......
717 717

  
718 718
    # Returns true if a given query string parameter exists.
719 719
    def has_key?(*args)
720
      @params.has_key?(*args)
720
      @params.key?(*args)
721 721
    end
722 722
    alias key? has_key?
723 723
    alias include? has_key?
lib/cgi/html.rb
311 311
                     { "METHOD" => method, "ACTION" => action,
312 312
                       "ENCTYPE" => enctype }
313 313
                   else
314
                     unless method.has_key?("METHOD")
314
                     unless method.key?("METHOD")
315 315
                       method["METHOD"] = "post"
316 316
                     end
317
                     unless method.has_key?("ENCTYPE")
317
                     unless method.key?("ENCTYPE")
318 318
                       method["ENCTYPE"] = enctype
319 319
                     end
320 320
                     method
......
409 409
      pretty = "  " if true == pretty
410 410
      buf = ""
411 411

  
412
      if attributes.has_key?("DOCTYPE")
412
      if attributes.key?("DOCTYPE")
413 413
        if attributes["DOCTYPE"]
414 414
          buf << attributes.delete("DOCTYPE")
415 415
        else
......
503 503
                     { "METHOD" => "post", "ACTION" => action,
504 504
                       "ENCTYPE" => enctype }
505 505
                   else
506
                     unless action.has_key?("METHOD")
506
                     unless action.key?("METHOD")
507 507
                       action["METHOD"] = "post"
508 508
                     end
509
                     unless action.has_key?("ENCTYPE")
509
                     unless action.key?("ENCTYPE")
510 510
                       action["ENCTYPE"] = enctype
511 511
                     end
512 512
                     action
lib/drb/drb.rb
863 863
                                  0,
864 864
                                  Socket::AI_PASSIVE)
865 865
      families = Hash[*infos.collect { |af, *_| af }.uniq.zip([]).flatten]
866
      return TCPServer.open('0.0.0.0', port) if families.has_key?('AF_INET')
867
      return TCPServer.open('::', port) if families.has_key?('AF_INET6')
866
      return TCPServer.open('0.0.0.0', port) if families.key?('AF_INET')
867
      return TCPServer.open('::', port) if families.key?('AF_INET6')
868 868
      return TCPServer.open(port)
869 869
      # :stopdoc:
870 870
    end
lib/mkmf.rb
197 197
        ['HDRDIR',        '$(rubyhdrdir)/ruby$(target_prefix)'],
198 198
        ['ARCHHDRDIR',    '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'],
199 199
      ]
200
    elsif $configure_args.has_key?('--vendor')
200
    elsif $configure_args.key?('--vendor')
201 201
      dirs = [
202 202
        ['BINDIR',        '$(bindir)'],
203 203
        ['RUBYCOMMONDIR', '$(vendordir)$(target_prefix)'],
......
1876 1876
      next unless /dir$/ =~ key
1877 1877
      mk << "#{key} = #{with_destdir(var)}\n"
1878 1878
    end
1879
    if !$extmk and !$configure_args.has_key?('--ruby') and
1879
    if !$extmk and !$configure_args.key?('--ruby') and
1880 1880
        sep = config_string('BUILD_FILE_SEPARATOR')
1881 1881
      sep = ":/=#{sep}"
1882 1882
    else
lib/net/imap.rb
410 410
    # A Net::IMAP::NoResponseError is raised if authentication fails.
411 411
    def authenticate(auth_type, *args)
412 412
      auth_type = auth_type.upcase
413
      unless @@authenticators.has_key?(auth_type)
413
      unless @@authenticators.key?(auth_type)
414 414
        raise ArgumentError,
415 415
          format('unknown auth type - "%s"', auth_type)
416 416
      end
......
1195 1195
    end
1196 1196

  
1197 1197
    def record_response(name, data)
1198
      unless @responses.has_key?(name)
1198
      unless @responses.key?(name)
1199 1199
        @responses[name] = []
1200 1200
      end
1201 1201
      @responses[name].push(data)
......
3506 3506
      STAGE_TWO = :stage_two
3507 3507

  
3508 3508
      def nc(nonce)
3509
        if @nc.has_key? nonce
3509
        if @nc.key? nonce
3510 3510
          @nc[nonce] = @nc[nonce] + 1
3511 3511
        else
3512 3512
          @nc[nonce] = 1
lib/net/telnet.rb
272 272
    #
273 273
    def initialize(options) # :yield: mesg
274 274
      @options = options
275
      @options["Host"]       = "localhost"   unless @options.has_key?("Host")
276
      @options["Port"]       = 23            unless @options.has_key?("Port")
277
      @options["Prompt"]     = /[$%#>] \z/n  unless @options.has_key?("Prompt")
278
      @options["Timeout"]    = 10            unless @options.has_key?("Timeout")
279
      @options["Waittime"]   = 0             unless @options.has_key?("Waittime")
280
      unless @options.has_key?("Binmode")
275
      @options["Host"]       = "localhost"   unless @options.key?("Host")
276
      @options["Port"]       = 23            unless @options.key?("Port")
277
      @options["Prompt"]     = /[$%#>] \z/n  unless @options.key?("Prompt")
278
      @options["Timeout"]    = 10            unless @options.key?("Timeout")
279
      @options["Waittime"]   = 0             unless @options.key?("Waittime")
280
      unless @options.key?("Binmode")
281 281
        @options["Binmode"]    = false
282 282
      else
283 283
        unless (true == @options["Binmode"] or false == @options["Binmode"])
......
285 285
        end
286 286
      end
287 287

  
288
      unless @options.has_key?("Telnetmode")
288
      unless @options.key?("Telnetmode")
289 289
        @options["Telnetmode"] = true
290 290
      else
291 291
        unless (true == @options["Telnetmode"] or false == @options["Telnetmode"])
......
295 295

  
296 296
      @telnet_option = { "SGA" => false, "BINARY" => false }
297 297

  
298
      if @options.has_key?("Output_log")
298
      if @options.key?("Output_log")
299 299
        @log = File.open(@options["Output_log"], 'a+')
300 300
        @log.sync = true
301 301
        @log.binmode
302 302
      end
303 303

  
304
      if @options.has_key?("Dump_log")
304
      if @options.key?("Dump_log")
305 305
        @dumplog = File.open(@options["Dump_log"], 'a+')
306 306
        @dumplog.sync = true
307 307
        @dumplog.binmode
......
328 328
        end
329 329
      end
330 330

  
331
      if @options.has_key?("Proxy")
331
      if @options.key?("Proxy")
332 332
        if @options["Proxy"].kind_of?(Net::Telnet)
333 333
          @sock = @options["Proxy"].sock
334 334
        elsif @options["Proxy"].kind_of?(IO)
......
339 339
      else
340 340
        message = "Trying " + @options["Host"] + "...\n"
341 341
        yield(message) if block_given?
342
        @log.write(message) if @options.has_key?("Output_log")
343
        @dumplog.log_dump('#', message) if @options.has_key?("Dump_log")
342
        @log.write(message) if @options.key?("Output_log")
343
        @dumplog.log_dump('#', message) if @options.key?("Dump_log")
344 344

  
345 345
        begin
346 346
          if @options["Timeout"] == false
......
353 353
        rescue Net::OpenTimeout
354 354
          raise Net::OpenTimeout, "timed out while opening a connection to the host"
355 355
        rescue
356
          @log.write($ERROR_INFO.to_s + "\n") if @options.has_key?("Output_log")
357
          @dumplog.log_dump('#', $ERROR_INFO.to_s + "\n") if @options.has_key?("Dump_log")
356
          @log.write($ERROR_INFO.to_s + "\n") if @options.key?("Output_log")
357
          @dumplog.log_dump('#', $ERROR_INFO.to_s + "\n") if @options.key?("Dump_log")
358 358
          raise
359 359
        end
360 360
        @sock.sync = true
......
362 362

  
363 363
        message = "Connected to " + @options["Host"] + ".\n"
364 364
        yield(message) if block_given?
365
        @log.write(message) if @options.has_key?("Output_log")
366
        @dumplog.log_dump('#', message) if @options.has_key?("Dump_log")
365
        @log.write(message) if @options.key?("Output_log")
366
        @dumplog.log_dump('#', message) if @options.key?("Dump_log")
367 367
      end
368 368

  
369 369
    end # initialize
......
531 531
      fail_eof = @options["FailEOF"]
532 532

  
533 533
      if options.kind_of?(Hash)
534
        prompt   = if options.has_key?("Match")
534
        prompt   = if options.key?("Match")
535 535
                     options["Match"]
536
                   elsif options.has_key?("Prompt")
536
                   elsif options.key?("Prompt")
537 537
                     options["Prompt"]
538
                   elsif options.has_key?("String")
538
                   elsif options.key?("String")
539 539
                     Regexp.new( Regexp.quote(options["String"]) )
540 540
                   end
541
        time_out = options["Timeout"]  if options.has_key?("Timeout")
542
        waittime = options["Waittime"] if options.has_key?("Waittime")
543
        fail_eof = options["FailEOF"]  if options.has_key?("FailEOF")
541
        time_out = options["Timeout"]  if options.key?("Timeout")
542
        waittime = options["Waittime"] if options.key?("Waittime")
543
        fail_eof = options["FailEOF"]  if options.key?("FailEOF")
544 544
      else
545 545
        prompt = options
546 546
      end
......
558 558
        end
559 559
        begin
560 560
          c = @sock.readpartial(1024 * 1024)
561
          @dumplog.log_dump('<', c) if @options.has_key?("Dump_log")
561
          @dumplog.log_dump('<', c) if @options.key?("Dump_log")
562 562
          if @options["Telnetmode"]
563 563
            c = rest + c
564 564
            if Integer(c.rindex(/#{IAC}#{SE}/no) || 0) <
......
588 588
             buf.gsub!(/#{EOL}/no, "\n")
589 589
           end
590 590
          end
591
          @log.print(buf) if @options.has_key?("Output_log")
591
          @log.print(buf) if @options.key?("Output_log")
592 592
          line += buf
593 593
          yield buf if block_given?
594 594
        rescue EOFError # End of file reached
......
611 611
      length = string.length
612 612
      while 0 < length
613 613
        IO::select(nil, [@sock])
614
        @dumplog.log_dump('>', string[-length..-1]) if @options.has_key?("Dump_log")
614
        @dumplog.log_dump('>', string[-length..-1]) if @options.key?("Dump_log")
615 615
        length -= @sock.syswrite(string[-length..-1])
616 616
      end
617 617
    end
......
682 682

  
683 683
      if options.kind_of?(Hash)
684 684
        string   = options["String"]
685
        match    = options["Match"]   if options.has_key?("Match")
686
        time_out = options["Timeout"] if options.has_key?("Timeout")
687
        fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
685
        match    = options["Match"]   if options.key?("Match")
686
        time_out = options["Timeout"] if options.key?("Timeout")
687
        fail_eof = options["FailEOF"] if options.key?("FailEOF")
688 688
      else
689 689
        string = options
690 690
      end
lib/rake/task_arguments.rb
80 80

  
81 81
    # Returns true if +key+ is one of the arguments
82 82
    def has_key?(key)
83
      @hash.has_key?(key)
83
      @hash.key?(key)
84 84
    end
85 85

  
86 86
    protected
87 87

  
88 88
    def lookup(name) # :nodoc:
89
      if @hash.has_key?(name)
89
      if @hash.key?(name)
90 90
        @hash[name]
91 91
      elsif @parent
92 92
        @parent.lookup(name)
lib/rexml/functions.rb
252 252
      map = {}
253 253
      0.upto(from.length - 1) { |pos|
254 254
        from_char = from[pos]
255
        unless map.has_key? from_char
255
        unless map.key? from_char
256 256
          map[from_char] =
257 257
          if pos < to.length
258 258
            to[pos]
......
264 264

  
265 265
      if ''.respond_to? :chars
266 266
        string(string).chars.collect { |c|
267
          if map.has_key? c then map[c] else c end
267
          if map.key? c then map[c] else c end
268 268
        }.compact.join
269 269
      else
270 270
        string(string).unpack('U*').collect { |c|
271
          if map.has_key? c then map[c] else c end
271
          if map.key? c then map[c] else c end
272 272
        }.compact.pack('U*')
273 273
      end
274 274
    end
lib/rexml/parsers/baseparser.rb
398 398
                    prefixes << prefix unless prefix == "xml"
399 399
                  end
400 400

  
401
                  if attributes.has_key?(attr_name)
401
                  if attributes.key?(attr_name)
402 402
                    msg = "Duplicate attribute #{attr_name.inspect}"
403 403
                    raise REXML::ParseException.new(msg, @source, self)
404 404
                  end
lib/rexml/parsers/sax2parser.rb
161 161
            copy = event[1].clone
162 162

  
163 163
            esub = proc { |match|
164
              if @entities.has_key?($1)
164
              if @entities.key?($1)
165 165
                @entities[$1].gsub(Text::REFERENCE, &esub)
166 166
              else
167 167
                match
lib/rss/atom.rb
236 236
          rel = link.rel || "alternate"
237 237
          next unless rel == "alternate"
238 238
          key = [link.hreflang, link.type]
239
          if link_infos.has_key?(key)
239
          if link_infos.key?(key)
240 240
            raise TooMuchTagError.new("link", tag_name)
241 241
          end
242 242
          link_infos[key] = true
lib/rss/parser.rb
205 205

  
206 206
      # test if this uri is registered against this name
207 207
      def uri_registered?(uri, name)
208
        @@registered_uris[name].has_key?(uri)
208
        @@registered_uris[name].key?(uri)
209 209
      end
210 210

  
211 211
      # record class_name for the supplied uri and tag_name
......
288 288
    def instruction(name, content)
289 289
      if name == "xml-stylesheet"
290 290
        params = parse_pi_content(content)
291
        if params.has_key?("href")
291
        if params.key?("href")
292 292
          @xml_stylesheets << XMLStyleSheet.new(params)
293 293
        end
294 294
      end
lib/rss/rss.rb
846 846
      end
847 847

  
848 848
      def install_ns(prefix, uri)
849
        if self::NSPOOL.has_key?(prefix)
849
        if self::NSPOOL.key?(prefix)
850 850
          raise OverlappedPrefixError.new(prefix)
851 851
        end
852 852
        self::NSPOOL[prefix] = uri
......
951 951
      prefix = ""
952 952
      prefix << "#{klass.required_prefix}_" if klass.required_prefix
953 953
      key = "#{prefix}#{tag_name.gsub(/-/, '_')}"
954
      if self.class.plural_forms.has_key?(key)
954
      if self.class.plural_forms.key?(key)
955 955
        ary = __send__("#{self.class.plural_forms[key]}")
956 956
        ary << next_element
957 957
      else
......
1051 1051
        value = __send__(alias_name || name)
1052 1052
        return nil if required and value.nil?
1053 1053
        next if value.nil?
1054
        return nil if attrs.has_key?(name)
1054
        return nil if attrs.key?(name)
1055 1055
        attrs[name] = value
1056 1056
      end
1057 1057
      attrs
......
1223 1223
    def tag_filter(tags)
1224 1224
      rv = {}
1225 1225
      tags.each do |tag|
1226
        rv[tag[0]] = [] unless rv.has_key?(tag[0])
1226
        rv[tag[0]] = [] unless rv.key?(tag[0])
1227 1227
        rv[tag[0]].push(tag[1])
1228 1228
      end
1229 1229
      rv
lib/rubygems/commands/push_command.rb
78 78
    # Always include this, even if it's nil
79 79
    args << @host
80 80

  
81
    if gem_data.spec.metadata.has_key?('allowed_push_host')
81
    if gem_data.spec.metadata.key?('allowed_push_host')
82 82
      args << gem_data.spec.metadata['allowed_push_host']
83 83
    end
84 84

  
lib/webrick/cgi.rb
54 54

  
55 55
    def initialize(*args)
56 56
      if defined?(MOD_RUBY)
57
        unless ENV.has_key?("GATEWAY_INTERFACE")
57
        unless ENV.key?("GATEWAY_INTERFACE")
58 58
          Apache.request.setup_cgi_env
59 59
        end
60 60
      end
lib/webrick/httpauth/digestauth.rb
172 172
          req_params = MustParams
173 173
        end
174 174
        req_params.each{|key|
175
          unless auth_req.has_key?(key)
175
          unless auth_req.key?(key)
176 176
            error('%s: parameter missing. "%s"', auth_req['username'], key)
177 177
            raise HTTPStatus::BadRequest
178 178
          end
......
195 195
          return false
196 196
        end
197 197

  
198
        if (@qop.nil? && auth_req.has_key?('qop')) ||
198
        if (@qop.nil? && auth_req.key?('qop')) ||
199 199
           (@qop && (! @qop.member?(auth_req['qop'])))
200 200
          error('%s: the qop is not allowed. "%s"',
201 201
                auth_req['username'], auth_req['qop'])
lib/webrick/httpservlet/cgihandler.rb
95 95
            res.status = $1.to_i
96 96
            header.delete('status')
97 97
          end
98
          if header.has_key?('location')
98
          if header.key?('location')
99 99
            # RFC 3875 6.2.3, 6.2.4
100 100
            res.status = 302 unless (300...400) === res.status
101 101
          end
102
          if header.has_key?('set-cookie')
102
          if header.key?('set-cookie')
103 103
            header['set-cookie'].each{|k|
104 104
              res.cookies << Cookie.parse_set_cookie(k)
105 105
            }
lib/webrick/httputils.rb
144 144
        when /^([A-Za-z0-9!\#$%&'*+\-.^_`|~]+):\s*(.*?)\s*\z/om
145 145
          field, value = $1, $2
146 146
          field.downcase!
147
          header[field] = [] unless header.has_key?(field)
147
          header[field] = [] unless header.key?(field)
148 148
          header[field] << value
149 149
        when /^\s+(.*?)\s*\z/om
150 150
          value = $1
......
375 375
          val = unescape_form(val.to_s)
376 376
          val = FormData.new(val)
377 377
          val.name = key
378
          if query.has_key?(key)
378
          if query.key?(key)
379 379
            query[key].append_data(val)
380 380
            next
381 381
          end
......
399 399
          if data
400 400
            data.chop!
401 401
            key = data.name
402
            if form_data.has_key?(key)
402
            if form_data.key?(key)
403 403
              form_data[key].append_data(data)
404 404
            else
405 405
              form_data[key] = data
lib/xmlrpc/parser.rb
177 177
    # * <code>'faultString'</code> key is a String
178 178
    def self.fault(hash)
179 179
      if hash.kind_of? Hash and hash.size == 2 and
180
        hash.has_key? "faultCode" and hash.has_key? "faultString" and
180
        hash.key? "faultCode" and hash.key? "faultString" and
181 181
        hash["faultCode"].kind_of? Integer and hash["faultString"].kind_of? String
182 182

  
183 183
        XMLRPC::FaultException.new(hash["faultCode"], hash["faultString"])