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
a46eacb2
Commit
a46eacb2
authored
May 08, 2013
by
Masaki Muranaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Hash#values_at to mruby-hash-ext gem.
parent
11e70f21
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
23 deletions
+68
-23
mrbgems/mruby-hash-ext/src/hash-ext.c
mrbgems/mruby-hash-ext/src/hash-ext.c
+62
-0
mrbgems/mruby-hash-ext/test/hash.rb
mrbgems/mruby-hash-ext/test/hash.rb
+6
-0
src/hash.c
src/hash.c
+0
-23
No files found.
mrbgems/mruby-hash-ext/src/hash-ext.c
0 → 100644
View file @
a46eacb2
/*
** hash.c - Hash class
**
** See Copyright Notice in mruby.h
*/
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/class.h"
#include "mruby/hash.h"
#include "mruby/khash.h"
#include "mruby/string.h"
#include "mruby/variable.h"
/*
* call-seq:
* hsh.values_at(key, ...) -> array
*
* Return an array containing the values associated with the given keys.
* Also see <code>Hash.select</code>.
*
* h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
* h.values_at("cow", "cat") #=> ["bovine", "feline"]
*/
mrb_value
mrb_hash_values_at
(
mrb_state
*
mrb
,
int
argc
,
mrb_value
*
argv
,
mrb_value
hash
)
{
mrb_value
result
=
mrb_ary_new_capa
(
mrb
,
argc
);
long
i
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
mrb_ary_push
(
mrb
,
result
,
mrb_hash_get
(
mrb
,
hash
,
argv
[
i
]));
}
return
result
;
}
static
mrb_value
hash_values_at
(
mrb_state
*
mrb
,
mrb_value
hash
)
{
mrb_value
*
argv
;
int
argc
;
mrb_get_args
(
mrb
,
"*"
,
&
argv
,
&
argc
);
return
mrb_hash_values_at
(
mrb
,
argc
,
argv
,
hash
);
}
void
mrb_mruby_hash_ext_gem_init
(
mrb_state
*
mrb
)
{
struct
RClass
*
h
;
h
=
mrb
->
hash_class
;
mrb_define_method
(
mrb
,
h
,
"values_at"
,
hash_values_at
,
MRB_ARGS_ANY
());
}
void
mrb_mruby_hash_ext_gem_final
(
mrb_state
*
mrb
)
{
}
mrbgems/mruby-hash-ext/test/hash.rb
View file @
a46eacb2
...
...
@@ -18,3 +18,9 @@ assert('Hash#merge!') do
'xyz_key'
=>
'xyz_value'
}
end
assert
(
'Hash#values_at'
)
do
h
=
{
"cat"
=>
"feline"
,
"dog"
=>
"canine"
,
"cow"
=>
"bovine"
}
result
=
h
.
values_at
(
"cow"
,
"cat"
)
result
==
[
"bovine"
,
"feline"
]
end
src/hash.c
View file @
a46eacb2
...
...
@@ -610,29 +610,6 @@ mrb_hash_shift(mrb_state *mrb, mrb_value hash)
*
*/
/*
* call-seq:
* hsh.values_at(key, ...) -> array
*
* Return an array containing the values associated with the given keys.
* Also see <code>Hash.select</code>.
*
* h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
* h.values_at("cow", "cat") #=> ["bovine", "feline"]
*/
mrb_value
mrb_hash_values_at
(
mrb_state
*
mrb
,
int
argc
,
mrb_value
*
argv
,
mrb_value
hash
)
{
mrb_value
result
=
mrb_ary_new_capa
(
mrb
,
argc
);
long
i
;
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
mrb_ary_push
(
mrb
,
result
,
mrb_hash_get
(
mrb
,
hash
,
argv
[
i
]));
}
return
result
;
}
/*
* call-seq:
* hsh.select {|key, value| block} -> a_hash
...
...
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