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
59cd24d4
Commit
59cd24d4
authored
Apr 04, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hash#replace should copy default as well; close #2004
parent
9f6d69ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
5 deletions
+17
-5
mrblib/hash.rb
mrblib/hash.rb
+5
-0
src/hash.c
src/hash.c
+3
-5
test/t/hash.rb
test/t/hash.rb
+9
-0
No files found.
mrblib/hash.rb
View file @
59cd24d4
...
...
@@ -152,6 +152,11 @@ class Hash
hash
.
each_key
{
|
k
|
self
[
k
]
=
hash
[
k
]
}
if
hash
.
default_proc
self
.
default_proc
=
hash
.
default_proc
elsif
hash
.
default
self
.
default
=
hash
.
default
end
self
end
# ISO 15.2.13.4.17
...
...
src/hash.c
View file @
59cd24d4
...
...
@@ -376,14 +376,12 @@ mrb_hash_aget(mrb_state *mrb, mrb_value self)
static
mrb_value
mrb_hash_default
(
mrb_state
*
mrb
,
mrb_value
hash
)
{
mrb_value
*
argv
;
int
argc
;
mrb_value
key
;
mrb_bool
given
;
mrb_get_args
(
mrb
,
"
*"
,
&
argv
,
&
argc
);
mrb_get_args
(
mrb
,
"
|o?"
,
&
key
,
&
given
);
if
(
MRB_RHASH_PROCDEFAULT_P
(
hash
))
{
if
(
argc
==
0
)
return
mrb_nil_value
();
key
=
argv
[
0
];
if
(
!
given
)
return
mrb_nil_value
();
return
mrb_funcall
(
mrb
,
RHASH_PROCDEFAULT
(
hash
),
"call"
,
2
,
hash
,
key
);
}
else
{
...
...
test/t/hash.rb
View file @
59cd24d4
...
...
@@ -230,6 +230,15 @@ assert('Hash#replace', '15.2.13.4.23') do
b
=
Hash
.
new
.
replace
(
a
)
assert_equal
({
'abc_key'
=>
'abc_value'
},
b
)
a
=
Hash
.
new
(
42
)
b
=
{}
b
.
replace
(
a
)
assert_equal
(
42
,
b
[
1
])
a
=
Hash
.
new
{
|
h
,
x
|
x
}
b
.
replace
(
a
)
assert_equal
(
127
,
b
[
127
])
end
assert
(
'Hash#shift'
,
'15.2.13.4.24'
)
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