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
d88191e7
Commit
d88191e7
authored
Apr 17, 2018
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement `Array#__svalue` in C.
parent
b51b21fc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
+16
-6
mrblib/array.rb
mrblib/array.rb
+0
-6
src/array.c
src/array.c
+16
-0
No files found.
mrblib/array.rb
View file @
d88191e7
...
...
@@ -184,12 +184,6 @@ class Array
return
block
.
call
if
ret
.
nil?
&&
block
ret
end
# internal method to convert multi-value to single value
def
__svalue
return
self
.
first
if
self
.
size
<
2
self
end
end
##
...
...
src/array.c
View file @
d88191e7
...
...
@@ -1207,6 +1207,21 @@ mrb_ary_cmp(mrb_state *mrb, mrb_value ary1)
return
ary2
;
}
/* internal method to convert multi-value to single value */
static
mrb_value
mrb_ary_svalue
(
mrb_state
*
mrb
,
mrb_value
ary
)
{
mrb_get_args
(
mrb
,
""
);
switch
(
RARRAY_LEN
(
ary
))
{
case
0
:
return
mrb_nil_value
();
case
1
:
return
RARRAY_PTR
(
ary
)[
0
];
default:
return
ary
;
}
}
void
mrb_init_array
(
mrb_state
*
mrb
)
{
...
...
@@ -1248,4 +1263,5 @@ mrb_init_array(mrb_state *mrb)
mrb_define_method
(
mrb
,
a
,
"__ary_eq"
,
mrb_ary_eq
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
a
,
"__ary_cmp"
,
mrb_ary_cmp
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
a
,
"__ary_index"
,
mrb_ary_index_m
,
MRB_ARGS_REQ
(
1
));
/* kept for mruby-array-ext */
mrb_define_method
(
mrb
,
a
,
"__svalue"
,
mrb_ary_svalue
,
MRB_ARGS_NONE
());
}
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