Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
e59c6a11
Commit
e59c6a11
authored
May 10, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2226 from yui-knk/hash-merge-error
Change to raise TypeError (Hash#merge, #merge!)
parents
3e2c5da4
658a00ba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
2 deletions
+10
-2
mrbgems/mruby-hash-ext/mrblib/hash.rb
mrbgems/mruby-hash-ext/mrblib/hash.rb
+1
-1
mrbgems/mruby-hash-ext/test/hash.rb
mrbgems/mruby-hash-ext/test/hash.rb
+4
-0
mrblib/hash.rb
mrblib/hash.rb
+1
-1
test/t/hash.rb
test/t/hash.rb
+4
-0
No files found.
mrbgems/mruby-hash-ext/mrblib/hash.rb
View file @
e59c6a11
...
...
@@ -22,7 +22,7 @@ class Hash
#
def
merge!
(
other
,
&
block
)
raise
"can't convert argument into Hash"
unless
other
.
respond_to?
(
:to_hash
)
raise
TypeError
,
"can't convert argument into Hash"
unless
other
.
respond_to?
(
:to_hash
)
if
block
other
.
each_key
{
|
k
|
self
[
k
]
=
(
self
.
has_key?
(
k
))?
block
.
call
(
k
,
self
[
k
],
other
[
k
]):
other
[
k
]
...
...
mrbgems/mruby-hash-ext/test/hash.rb
View file @
e59c6a11
...
...
@@ -16,6 +16,10 @@ assert('Hash#merge!') do
'xyz_key'
=>
'xyz_value'
},
result_1
)
assert_equal
({
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'cba_value'
,
'xyz_key'
=>
'xyz_value'
},
result_2
)
assert_raise
(
TypeError
)
do
{
'abc_key'
=>
'abc_value'
}.
merge!
"a"
end
end
assert
(
'Hash#values_at'
)
do
...
...
mrblib/hash.rb
View file @
e59c6a11
...
...
@@ -179,7 +179,7 @@ class Hash
# ISO 15.2.13.4.22
def
merge
(
other
,
&
block
)
h
=
{}
raise
"can't convert argument into Hash"
unless
other
.
respond_to?
(
:to_hash
)
raise
TypeError
,
"can't convert argument into Hash"
unless
other
.
respond_to?
(
:to_hash
)
other
=
other
.
to_hash
self
.
each_key
{
|
k
|
h
[
k
]
=
self
[
k
]}
if
block
...
...
test/t/hash.rb
View file @
e59c6a11
...
...
@@ -223,6 +223,10 @@ assert('Hash#merge', '15.2.13.4.22') do
'xyz_key'
=>
'xyz_value'
},
result_1
)
assert_equal
({
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'cba_value'
,
'xyz_key'
=>
'xyz_value'
},
result_2
)
assert_raise
(
TypeError
)
do
{
'abc_key'
=>
'abc_value'
}.
merge
"a"
end
end
assert
(
'Hash#replace'
,
'15.2.13.4.23'
)
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment