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
daf83946
Commit
daf83946
authored
Mar 23, 2016
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add #dig to Array,Hash and Struct
parent
4c1ce0f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
0 deletions
+51
-0
mrbgems/mruby-array-ext/mrblib/array.rb
mrbgems/mruby-array-ext/mrblib/array.rb
+17
-0
mrbgems/mruby-hash-ext/mrblib/hash.rb
mrbgems/mruby-hash-ext/mrblib/hash.rb
+17
-0
mrbgems/mruby-struct/mrblib/struct.rb
mrbgems/mruby-struct/mrblib/struct.rb
+17
-0
No files found.
mrbgems/mruby-array-ext/mrblib/array.rb
View file @
daf83946
...
@@ -744,4 +744,21 @@ class Array
...
@@ -744,4 +744,21 @@ class Array
def
to_ary
def
to_ary
self
self
end
end
##
# call-seq:
# ary.dig(idx, ...) -> object
#
# Extracts the nested value specified by the sequence of <i>idx</i>
# objects by calling +dig+ at each step, returning +nil+ if any
# intermediate step is +nil+.
#
def
dig
(
idx
,
*
args
)
n
=
self
[
idx
]
if
args
.
size
>
0
n
&
.
dig
(
*
args
)
else
n
end
end
end
end
mrbgems/mruby-hash-ext/mrblib/hash.rb
View file @
daf83946
...
@@ -365,4 +365,21 @@ class Hash
...
@@ -365,4 +365,21 @@ class Hash
key?
(
key
)
and
self
[
key
]
==
val
key?
(
key
)
and
self
[
key
]
==
val
}
}
end
end
##
# call-seq:
# hsh.dig(key,...) -> object
#
# Extracts the nested value specified by the sequence of <i>key</i>
# objects by calling +dig+ at each step, returning +nil+ if any
# intermediate step is +nil+.
#
def
dig
(
idx
,
*
args
)
n
=
self
[
idx
]
if
args
.
size
>
0
n
&
.
dig
(
*
args
)
else
n
end
end
end
end
mrbgems/mruby-struct/mrblib/struct.rb
View file @
daf83946
...
@@ -82,5 +82,22 @@ if Object.const_defined?(:Struct)
...
@@ -82,5 +82,22 @@ if Object.const_defined?(:Struct)
#
#
alias
to_s
inspect
alias
to_s
inspect
end
end
##
# call-seq:
# hsh.dig(key,...) -> object
#
# Extracts the nested value specified by the sequence of <i>key</i>
# objects by calling +dig+ at each step, returning +nil+ if any
# intermediate step is +nil+.
#
def
dig
(
idx
,
*
args
)
n
=
self
[
idx
]
if
args
.
size
>
0
n
&
.
dig
(
*
args
)
else
n
end
end
end
end
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