summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-hash-ext/mrblib/hash.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-03-23 01:14:46 +0900
committerGitHub <[email protected]>2017-03-23 01:14:46 +0900
commit41f5c5b2c7e0411ae416bd7915e8772c569f3182 (patch)
treeb94ea6c03ed32c83683c16449751c185dc59e40f /mrbgems/mruby-hash-ext/mrblib/hash.rb
parent8ca9823196f52a3a63006bef703247f0f982bb80 (diff)
parente72e50b5d57d4ad003da8a1531263f7795c27db5 (diff)
downloadmruby-41f5c5b2c7e0411ae416bd7915e8772c569f3182.tar.gz
mruby-41f5c5b2c7e0411ae416bd7915e8772c569f3182.zip
Merge pull request #3529 from kou/hash-ext-sub-class
Hash sub class creates new sub class objects instead of Hash
Diffstat (limited to 'mrbgems/mruby-hash-ext/mrblib/hash.rb')
-rw-r--r--mrbgems/mruby-hash-ext/mrblib/hash.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb
index db4db42e8..31ff6d685 100644
--- a/mrbgems/mruby-hash-ext/mrblib/hash.rb
+++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb
@@ -28,11 +28,11 @@ class Hash
if length == 1
o = object[0]
if o.respond_to?(:to_hash)
- h = Hash.new
+ h = self.new
object[0].to_hash.each { |k, v| h[k] = v }
return h
elsif o.respond_to?(:to_a)
- h = Hash.new
+ h = self.new
o.to_a.each do |i|
raise ArgumentError, "wrong element type #{i.class} (expected array)" unless i.respond_to?(:to_a)
k, v = nil
@@ -53,7 +53,7 @@ class Hash
unless length % 2 == 0
raise ArgumentError, 'odd number of arguments for Hash'
end
- h = Hash.new
+ h = self.new
0.step(length - 2, 2) do |i|
h[object[i]] = object[i + 1]
end
@@ -211,7 +211,7 @@ class Hash
#
def invert
- h = Hash.new
+ h = self.class.new
self.each {|k, v| h[v] = k }
h
end