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
50f54529
Commit
50f54529
authored
Sep 19, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
to_hash/to_a check in Hash[] should only be done when only one argument is given; ref #2594
parent
02b2ac8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
22 deletions
+27
-22
mrbgems/mruby-hash-ext/mrblib/hash.rb
mrbgems/mruby-hash-ext/mrblib/hash.rb
+27
-22
No files found.
mrbgems/mruby-hash-ext/mrblib/hash.rb
View file @
50f54529
...
@@ -24,32 +24,37 @@ class Hash
...
@@ -24,32 +24,37 @@ class Hash
#
#
def
self
.
[]
(
*
object
)
def
self
.
[]
(
*
object
)
o
=
object
[
0
]
length
=
object
.
length
if
o
.
respond_to?
(
:to_hash
)
if
length
==
1
h
=
Hash
.
new
o
=
object
[
0
]
object
[
0
].
to_hash
.
each
{
|
k
,
v
|
h
[
k
]
=
v
}
if
o
.
respond_to?
(
:to_hash
)
return
h
h
=
Hash
.
new
elsif
o
.
respond_to?
(
:to_a
)
object
[
0
].
to_hash
.
each
{
|
k
,
v
|
h
[
k
]
=
v
}
h
=
Hash
.
new
return
h
o
.
to_a
.
each
do
|
i
|
elsif
o
.
respond_to?
(
:to_a
)
raise
ArgumentError
,
"wrong element type
#{
i
.
class
}
(expected array)"
unless
i
.
respond_to?
(
:to_a
)
h
=
Hash
.
new
k
,
v
=
nil
o
.
to_a
.
each
do
|
i
|
case
i
.
size
raise
ArgumentError
,
"wrong element type
#{
i
.
class
}
(expected array)"
unless
i
.
respond_to?
(
:to_a
)
when
2
k
,
v
=
nil
k
=
i
[
0
]
case
i
.
size
v
=
i
[
1
]
when
2
when
1
k
=
i
[
0
]
k
=
i
[
0
]
v
=
i
[
1
]
else
when
1
raise
ArgumentError
,
"invalid number of elements (
#{
i
.
size
}
for 1..2)"
k
=
i
[
0
]
else
raise
ArgumentError
,
"invalid number of elements (
#{
i
.
size
}
for 1..2)"
end
h
[
k
]
=
v
end
end
h
[
k
]
=
v
return
h
end
end
return
h
end
end
raise
ArgumentError
,
'odd number of arguments for Hash'
unless
object
.
length
%
2
==
0
unless
length
%
2
==
0
raise
ArgumentError
,
'odd number of arguments for Hash'
end
h
=
Hash
.
new
h
=
Hash
.
new
0
.
step
(
object
.
length
-
2
,
2
)
do
|
i
|
0
.
step
(
length
-
2
,
2
)
do
|
i
|
h
[
object
[
i
]]
=
object
[
i
+
1
]
h
[
object
[
i
]]
=
object
[
i
+
1
]
end
end
h
h
...
...
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