summaryrefslogtreecommitdiffhomepage
path: root/mrblib
diff options
context:
space:
mode:
Diffstat (limited to 'mrblib')
-rw-r--r--mrblib/array.rb2
-rw-r--r--mrblib/hash.rb14
-rw-r--r--mrblib/string.rb11
3 files changed, 10 insertions, 17 deletions
diff --git a/mrblib/array.rb b/mrblib/array.rb
index 13c5d646c..16c602ba0 100644
--- a/mrblib/array.rb
+++ b/mrblib/array.rb
@@ -66,7 +66,7 @@ class Array
#
# ISO 15.2.12.5.15
def initialize(size=0, obj=nil, &block)
- raise TypeError, "expected Integer for 1st argument" unless size.kind_of? Integral
+ size = size.__to_int
raise ArgumentError, "negative array size" if size < 0
self.clear
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index 96029a230..1cd039c45 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -12,9 +12,7 @@ class Hash
# ISO 15.2.13.4.1
def ==(hash)
return true if self.equal?(hash)
- begin
- hash = hash.to_hash
- rescue NoMethodError
+ unless Hash === hash
return false
end
return false if self.size != hash.size
@@ -32,9 +30,7 @@ class Hash
# ISO 15.2.13.4.32 (x)
def eql?(hash)
return true if self.equal?(hash)
- begin
- hash = hash.to_hash
- rescue NoMethodError
+ unless Hash === hash
return false
end
return false if self.size != hash.size
@@ -154,9 +150,8 @@ class Hash
#
# ISO 15.2.13.4.23
def replace(hash)
- raise TypeError, "can't convert argument into Hash" unless hash.respond_to?(:to_hash)
+ raise TypeError, "Hash required (#{hash.class} given)" unless Hash === hash
self.clear
- hash = hash.to_hash
hash.each_key{|k|
self[k] = hash[k]
}
@@ -179,8 +174,7 @@ class Hash
#
# ISO 15.2.13.4.22
def merge(other, &block)
- raise TypeError, "can't convert argument into Hash" unless other.respond_to?(:to_hash)
- other = other.to_hash
+ raise TypeError, "Hash required (#{other.class} given)" unless Hash === other
h = self.dup
if block
other.each_key{|k|
diff --git a/mrblib/string.rb b/mrblib/string.rb
index 07b80b340..397603e9d 100644
--- a/mrblib/string.rb
+++ b/mrblib/string.rb
@@ -12,7 +12,7 @@ class String
def each_line(rs = "\n", &block)
return to_enum(:each_line, rs, &block) unless block
return block.call(self) if rs.nil?
- rs = rs.to_str
+ rs = rs.__to_str
offset = 0
rs_len = rs.length
this = dup
@@ -67,7 +67,7 @@ class String
block = nil
end
if !replace.nil? || !block
- replace = replace.to_str
+ replace = replace.__to_str
end
offset = 0
result = []
@@ -129,12 +129,12 @@ class String
end
pattern, replace = *args
- pattern = pattern.to_str
+ pattern = pattern.__to_str
if args.length == 2 && block
block = nil
end
unless block
- replace = replace.to_str
+ replace = replace.__to_str
end
result = []
this = dup
@@ -245,14 +245,13 @@ class String
##
# ISO 15.2.10.5.3
def =~(re)
- raise TypeError, "type mismatch: String given" if re.respond_to? :to_str
re =~ self
end
##
# ISO 15.2.10.5.27
def match(re, &block)
- if re.respond_to? :to_str
+ if String === re
if Object.const_defined?(:Regexp)
r = Regexp.new(re)
r.match(self, &block)