Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mrbgems/mruby-array-ext/mrblib/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def transpose

column_count = nil
self.each do |row|
raise TypeError unless row.is_a?(Array)
raise TypeError unless Array === row
column_count ||= row.size
raise IndexError, 'element size differs' unless column_count == row.size
end
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-compar-ext/mrblib/compar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module Comparable
def clamp(min, max=nil)

if max.nil?
if min.kind_of?(Range)
if Range === min
max = min.end
if !max.nil? && min.exclude_end?
raise ArgumentError, "cannot clamp with an exclusive range"
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-complex/mrblib/complex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def -@
# Complex(2, 3) <=> 1 #=> 1
#
def <=>(other)
return nil unless other.kind_of?(Numeric)
return nil unless Numeric === other
self.to_f <=> other.to_f
rescue
nil
Expand Down
4 changes: 2 additions & 2 deletions mrbgems/mruby-enum-ext/mrblib/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -785,14 +785,14 @@ def to_h(&blk)
if blk
self.each do |v|
v = blk.call(v)
raise TypeError, "wrong element type #{v.class} (expected Array)" unless v.is_a? Array
raise TypeError, "wrong element type #{v.class} (expected Array)" unless Array === v
raise ArgumentError, "element has wrong array length (expected 2, was #{v.size})" if v.size != 2
h[v[0]] = v[1]
end
else
self.each do |*v|
v = v.__svalue
raise TypeError, "wrong element type #{v.class} (expected Array)" unless v.is_a? Array
raise TypeError, "wrong element type #{v.class} (expected Array)" unless Array === v
raise ArgumentError, "element has wrong array length (expected 2, was #{v.size})" if v.size != 2
h[v[0]] = v[1]
end
Expand Down
4 changes: 2 additions & 2 deletions mrbgems/mruby-enumerator/mrblib/enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def initialize(obj=NONE, meth=:each, *args, **kwd, &block)
end

private def initialize_copy(obj)
raise TypeError, "can't copy type #{obj.class}" unless obj.kind_of? Enumerator
raise TypeError, "can't copy type #{obj.class}" unless Enumerator === obj
raise TypeError, "can't copy execution context" if obj.instance_eval{@fib}
meth = args = kwd = fib = nil
obj.instance_eval {
Expand Down Expand Up @@ -780,7 +780,7 @@ def chunk(&block)
when last_value
arr << element
else
raise 'symbols beginning with an underscore are reserved' if value.is_a?(Symbol) && value.to_s[0] == '_'
raise 'symbols beginning with an underscore are reserved' if Symbol === value && value.to_s[0] == '_'
y.yield [last_value, arr] if arr.size > 0
last_value, arr = value, [element]
end
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-io/mrblib/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class File < IO
# f = File.new("tmpfile", "a")
#
def initialize(fd_or_path, mode = "r", perm = 0666)
if fd_or_path.kind_of? Integer
if Integer === fd_or_path
super(fd_or_path, mode)
else
@path = fd_or_path
Expand Down
8 changes: 4 additions & 4 deletions mrbgems/mruby-range-ext/mrblib/range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def max(&block)
raise RangeError, "cannot get the maximum of endless range" if last.nil?

# fast path for numerics
if val.kind_of?(Numeric) && last.kind_of?(Numeric)
raise TypeError if exclude_end? && !last.kind_of?(Integer)
if Numeric === val && Numeric === last
raise TypeError if exclude_end? && !(Integer === last)
return nil if val > last
return nil if val == last && exclude_end?

Expand Down Expand Up @@ -109,7 +109,7 @@ def min(&block)
return val if last.nil?

# fast path for numerics
if val.kind_of?(Numeric) && last.kind_of?(Numeric)
if Numeric === val && Numeric === last
return nil if val > last
return nil if val == last && exclude_end?

Expand All @@ -132,7 +132,7 @@ def min(&block)
# (1..5).overlap?(7..9) #=> false
#
def overlap?(other)
raise TypeError, "argument must be a range" unless other.kind_of?(Range)
raise TypeError, "argument must be a range" unless Range === other

self_begin = self.begin
other_end = other.end
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-rational/mrblib/rational.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def to_s
# Rational(1, 3) <=> 0.3 #=> 1
#
def <=>(other)
return nil unless other.kind_of?(Numeric)
return nil unless Numeric === other
self.to_f <=> other.to_f
rescue
nil
Expand Down
8 changes: 4 additions & 4 deletions mrbgems/mruby-socket/mrblib/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Addrinfo
#
def initialize(sockaddr, family=Socket::PF_UNSPEC, socktype=0, protocol=0)
@hostname = nil
if sockaddr.is_a? Array
if Array === sockaddr
sary = sockaddr
if sary[0] == 'AF_INET' || sary[0] == 'AF_INET6'
@sockaddr = Socket.sockaddr_in(sary[1], sary[3])
Expand Down Expand Up @@ -870,7 +870,7 @@ def accept_nonblock
# sock.bind(addrinfo)
#
def bind(sockaddr)
sockaddr = sockaddr.to_sockaddr if sockaddr.is_a? Addrinfo
sockaddr = sockaddr.to_sockaddr if Addrinfo === sockaddr
Socket._bind(self.fileno, sockaddr)
0
end
Expand All @@ -885,7 +885,7 @@ def bind(sockaddr)
# sock.connect(addrinfo)
#
def connect(sockaddr)
sockaddr = sockaddr.to_sockaddr if sockaddr.is_a? Addrinfo
sockaddr = sockaddr.to_sockaddr if Addrinfo === sockaddr
Socket._connect(self.fileno, sockaddr)
0
end
Expand Down Expand Up @@ -948,7 +948,7 @@ class UNIXSocket < BasicSocket
# UNIXSocket.new("/tmp/socket") { |s| s.write("data") }
#
def initialize(path, &block)
if self.is_a? UNIXServer
if UNIXServer === self
super(path, "r")
else
super(Socket._socket(Socket::AF_UNIX, Socket::SOCK_STREAM, 0), "r+")
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-sprintf/mrblib/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class String
# "%{foo}f" % { :foo => 1 } #=> "1f"
#
def %(args)
if args.is_a? Array
if Array === args
sprintf(self, *args)
else
sprintf(self, args)
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-string-ext/mrblib/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def lines(&blk)
# "07".upto("11").to_a #=> ["07", "08", "09", "10", "11"]
def upto(max, exclusive=false, &block)
return to_enum(:upto, max, exclusive) unless block
raise TypeError, "no implicit conversion of #{max.class} into String" unless max.kind_of? String
raise TypeError, "no implicit conversion of #{max.class} into String" unless String === max

len = self.length
maxlen = max.length
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-symbol-ext/mrblib/symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def upcase
# Case-insensitive version of `Symbol#<=>`.

def casecmp(other)
return nil unless other.kind_of?(Symbol)
return nil unless Symbol === other
lhs = self.to_s; lhs.upcase!
rhs = other.to_s.upcase
lhs <=> rhs
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-task/mrblib/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def push(obj)
def pop(non_block = false, timeout_ms: nil)
unless timeout_ms.nil?
raise ArgumentError, "timeout cannot be combined with non_block" if non_block
raise TypeError, "timeout_ms must be an Integer" unless timeout_ms.is_a?(Integer)
raise TypeError, "timeout_ms must be an Integer" unless Integer === timeout_ms
raise ArgumentError, "timeout_ms must be non-negative" if timeout_ms < 0
end
deadline = timeout_ms.nil? ? nil : __deadline(timeout_ms)
Expand Down
2 changes: 1 addition & 1 deletion mrblib/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def collect!(&block)
idx = 0
len = size
while idx < len
self[idx] = block.call(self[idx])
self[idx] = yield(self[idx])
idx += 1
end
self
Expand Down
22 changes: 11 additions & 11 deletions mrblib/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Enumerable
# ISO 15.3.2.2.1
def all?(&block)
if block
self.each {|*val| return false unless block.call(*val)}
self.each {|*val| return false unless yield(*val)}
else
self.each {|*val| return false unless val.__svalue}
end
Expand All @@ -42,7 +42,7 @@ def all?(&block)
# ISO 15.3.2.2.2
def any?(&block)
if block
self.each {|*val| return true if block.call(*val)}
self.each {|*val| return true if yield(*val)}
else
self.each {|*val| return true if val.__svalue}
end
Expand All @@ -60,7 +60,7 @@ def collect(&block)
return to_enum(:collect) unless block

ary = []
self.each {|*val| ary.push(block.call(*val))}
self.each {|*val| ary.push(yield(*val))}
ary
end

Expand All @@ -76,7 +76,7 @@ def detect(ifnone=nil, &block)
return to_enum(:detect, ifnone) unless block

self.each {|*val|
if block.call(*val)
if yield(*val)
return val.__svalue
end
}
Expand All @@ -95,7 +95,7 @@ def each_with_index(&block)

i = 0
self.each {|*val|
block.call(val.__svalue, i)
yield(val.__svalue, i)
i += 1
}
self
Expand Down Expand Up @@ -133,7 +133,7 @@ def find_all(&block)

ary = []
self.each {|*val|
ary.push(val.__svalue) if block.call(*val)
ary.push(val.__svalue) if yield(*val)
}
ary
end
Expand All @@ -151,7 +151,7 @@ def grep(pattern, &block)
self.each {|*val|
sv = val.__svalue
if pattern === sv
ary.push((block)? block.call(*val): sv)
ary.push((block)? yield(*val): sv)
end
}
ary
Expand Down Expand Up @@ -231,7 +231,7 @@ def max(&block)
flag = false
else
if block
result = val if block.call(val, result) > 0
result = val if yield(val, result) > 0
else
result = val if (val <=> result) > 0
end
Expand All @@ -258,7 +258,7 @@ def min(&block)
flag = false
else
if block
result = val if block.call(val, result) < 0
result = val if yield(val, result) < 0
else
result = val if (val <=> result) < 0
end
Expand Down Expand Up @@ -289,7 +289,7 @@ def partition(&block)
ary_T = []
ary_F = []
self.each {|*val|
if block.call(*val)
if yield(*val)
ary_T.push(val.__svalue)
else
ary_F.push(val.__svalue)
Expand All @@ -310,7 +310,7 @@ def reject(&block)

ary = []
self.each {|*val|
ary.push(val.__svalue) unless block.call(*val)
ary.push(val.__svalue) unless yield(*val)
}
ary
end
Expand Down
18 changes: 9 additions & 9 deletions mrblib/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Hash
# ISO 15.2.13.4.8
def delete(key, &block)
if block && !self.has_key?(key)
return block.call(key)
return yield(key)
end
self.__delete(key)
end
Expand Down Expand Up @@ -59,7 +59,7 @@ def each(&block)
len = self.size
i = 0
while i < len
block.call([keys[i], vals[i]])
yield([keys[i], vals[i]])
i += 1
end
self
Expand Down Expand Up @@ -87,7 +87,7 @@ def each(&block)
def each_key(&block)
return to_enum(:each_key) unless block

self.keys.each {|k| block.call(k)}
self.keys.each {|k| yield(k)}
self
end

Expand All @@ -112,7 +112,7 @@ def each_key(&block)
def each_value(&block)
return to_enum(:each_value) unless block

self.values.each {|v| block.call(v)}
self.values.each {|v| yield(v)}
self
end

Expand Down Expand Up @@ -148,7 +148,7 @@ def merge(*others, &block)
i += 1
raise TypeError, "Hash required (#{other.class} given)" unless Hash === other
other.each_key {|k|
h[k] = (self.has_key?(k))? block.call(k, self[k], other[k]): other[k]
h[k] = (self.has_key?(k))? yield(k, self[k], other[k]): other[k]
}
end
h
Expand All @@ -169,7 +169,7 @@ def reject!(&block)

keys = []
self.each {|k,v|
if block.call([k, v])
if yield([k, v])
keys.push(k)
end
}
Expand Down Expand Up @@ -200,7 +200,7 @@ def reject(&block)

h = {}
self.each {|k,v|
unless block.call([k, v])
unless yield([k, v])
h[k] = v
end
}
Expand All @@ -222,7 +222,7 @@ def select!(&block)

keys = []
self.each {|k,v|
unless block.call([k, v])
unless yield([k, v])
keys.push(k)
end
}
Expand Down Expand Up @@ -253,7 +253,7 @@ def select(&block)

h = {}
self.each {|k,v|
if block.call([k, v])
if yield([k, v])
h[k] = v
end
}
Expand Down
Loading
Loading