Commit 0d055559 authored by INOUE Yasuyuki's avatar INOUE Yasuyuki

Use #nil? instead of == nil.

parent 71f2975a
......@@ -217,7 +217,7 @@ class Array
# [ "a", "b", "c" ].compact! #=> nil
#
def compact!
result = self.select { |e| e != nil }
result = self.select { |e| !e.nil? }
if result.size == self.size
nil
else
......@@ -262,7 +262,7 @@ class Array
#
def fetch(n=nil, ifnone=NONE, &block)
warn "block supersedes default value argument" if n != nil && ifnone != NONE && block
warn "block supersedes default value argument" if !n.nil? && ifnone != NONE && block
idx = n
if idx < 0
......@@ -312,51 +312,51 @@ class Array
#
def fill(arg0=nil, arg1=nil, arg2=nil, &block)
if arg0 == nil && arg1 == nil && arg2 == nil && !block
if arg0.nil? && arg1.nil? && arg2.nil? && !block
raise ArgumentError, "wrong number of arguments (0 for 1..3)"
end
beg = len = 0
ary = []
if block
if arg0 == nil && arg1 == nil && arg2 == nil
if arg0.nil? && arg1.nil? && arg2.nil?
# ary.fill { |index| block } -> ary
beg = 0
len = self.size
elsif arg0 != nil && arg0.kind_of?(Range)
elsif !arg0.nil? && arg0.kind_of?(Range)
# ary.fill(range) { |index| block } -> ary
beg = arg0.begin
beg += self.size if beg < 0
len = arg0.end
len += self.size if len < 0
len += 1 unless arg0.exclude_end?
elsif arg0 != nil
elsif !arg0.nil?
# ary.fill(start [, length] ) { |index| block } -> ary
beg = arg0
beg += self.size if beg < 0
if arg1 == nil
if arg1.nil?
len = self.size
else
len = arg0 + arg1
end
end
else
if arg0 != nil && arg1 == nil && arg2 == nil
if !arg0.nil? && arg1.nil? && arg2.nil?
# ary.fill(obj) -> ary
beg = 0
len = self.size
elsif arg0 != nil && arg1 != nil && arg1.kind_of?(Range)
elsif !arg0.nil? && !arg1.nil? && arg1.kind_of?(Range)
# ary.fill(obj, range ) -> ary
beg = arg1.begin
beg += self.size if beg < 0
len = arg1.end
len += self.size if len < 0
len += 1 unless arg1.exclude_end?
elsif arg0 != nil && arg1 != nil
elsif !arg0.nil? && !arg1.nil?
# ary.fill(obj, start [, length]) -> ary
beg = arg1
beg += self.size if beg < 0
if arg2 == nil
if arg2.nil?
len = self.size
else
len = beg + arg2
......@@ -582,7 +582,7 @@ class Array
elsif v == true
satisfied = true
smaller = true
elsif v == false || v == nil
elsif v == false || v.nil?
smaller = false
end
if smaller
......
......@@ -515,7 +515,7 @@ module Enumerable
#
def each_with_object(obj=nil, &block)
raise ArgumentError, "wrong number of arguments (0 for 1)" if obj == nil
raise ArgumentError, "wrong number of arguments (0 for 1)" if obj.nil?
return to_enum(:each_with_object, obj) unless block
......@@ -574,10 +574,10 @@ module Enumerable
#
def cycle(n=nil, &block)
return to_enum(:cycle, n) if !block && n == nil
return to_enum(:cycle, n) if !block && n.nil?
ary = []
if n == nil
if n.nil?
self.each do|*val|
ary.push val
block.call(*val)
......
......@@ -164,9 +164,9 @@ class String
# string #=> "thsa sting"
#
def slice!(arg1, arg2=nil)
raise "wrong number of arguments (for 1..2)" if arg1 == nil && arg2 == nil
raise "wrong number of arguments (for 1..2)" if arg1.nil? && arg2.nil?
if arg1 != nil && arg2 != nil
if !arg1.nil? && !arg2.nil?
idx = arg1
idx += self.size if arg1 < 0
if idx >= 0 && idx <= self.size && arg2 > 0
......@@ -196,8 +196,8 @@ class String
return nil
end
end
unless str == nil || str == ""
if arg1 != nil && arg2 !=nil
unless str.nil? || str == ""
if !arg1.nil? && !arg2.nil?
idx = arg1 >= 0 ? arg1 : self.size+arg1
str2 = self[0...idx] + self[idx+arg2..-1].to_s
else
......@@ -207,13 +207,13 @@ class String
str2 = self[0...idx] + self[idx2+1..-1].to_s
elsif arg1.kind_of?(String)
idx = self.index(arg1)
str2 = self[0...idx] + self[idx+arg1.size..-1] unless idx == nil
str2 = self[0...idx] + self[idx+arg1.size..-1] unless idx.nil?
else
idx = arg1 >= 0 ? arg1 : self.size+arg1
str2 = self[0...idx] + self[idx+1..-1].to_s
end
end
self.replace(str2) unless str2 == nil
self.replace(str2) unless str2.nil?
end
str
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment