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
2a9ccf24
Unverified
Commit
2a9ccf24
authored
Jan 04, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jan 04, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4211 from dearblue/proc-composition
Add proc composition feature (CRuby-2.6 compatible)
parents
acb1fdc7
fc20d018
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
0 deletions
+48
-0
mrbgems/mruby-method/mrblib/method.rb
mrbgems/mruby-method/mrblib/method.rb
+8
-0
mrbgems/mruby-method/test/method.rb
mrbgems/mruby-method/test/method.rb
+19
-0
mrbgems/mruby-proc-ext/mrblib/proc.rb
mrbgems/mruby-proc-ext/mrblib/proc.rb
+8
-0
mrbgems/mruby-proc-ext/test/proc.rb
mrbgems/mruby-proc-ext/test/proc.rb
+13
-0
No files found.
mrbgems/mruby-method/mrblib/method.rb
View file @
2a9ccf24
...
...
@@ -17,4 +17,12 @@ class Method
def
name
@name
end
def
<<
(
other
)
->
(
*
args
,
&
block
)
{
call
(
other
.
call
(
*
args
,
&
block
))
}
end
def
>>
(
other
)
->
(
*
args
,
&
block
)
{
other
.
call
(
call
(
*
args
,
&
block
))
}
end
end
mrbgems/mruby-method/test/method.rb
View file @
2a9ccf24
...
...
@@ -371,6 +371,25 @@ assert "Method#initialize_copy" do
assert_equal
(
m1
,
m2
)
end
assert
"Method#<< and Method#>>"
do
obj
=
Object
.
new
class
<<
obj
def
mul2
(
n
);
n
*
2
;
end
def
add3
(
n
);
n
+
3
;
end
end
f
=
obj
.
method
(
:mul2
)
g
=
obj
.
method
(
:add3
)
m1
=
f
<<
g
assert_kind_of
Proc
,
m1
assert_equal
16
,
m1
.
call
(
5
)
m2
=
f
>>
g
assert_kind_of
Proc
,
m2
assert_equal
13
,
m2
.
call
(
5
)
end
assert
'UnboundMethod#arity'
do
c
=
Class
.
new
{
def
foo
(
a
,
b
)
...
...
mrbgems/mruby-proc-ext/mrblib/proc.rb
View file @
2a9ccf24
...
...
@@ -39,4 +39,12 @@ class Proc
make_curry
.
call
end
def
<<
(
other
)
->
(
*
args
,
&
block
)
{
call
(
other
.
call
(
*
args
,
&
block
))
}
end
def
>>
(
other
)
->
(
*
args
,
&
block
)
{
other
.
call
(
call
(
*
args
,
&
block
))
}
end
end
mrbgems/mruby-proc-ext/test/proc.rb
View file @
2a9ccf24
...
...
@@ -77,6 +77,19 @@ assert('Kernel#proc') do
end
end
assert
"Proc#<< and Proc#>>"
do
add3
=
->
(
n
)
{
n
+
3
}
mul2
=
->
(
n
)
{
n
*
2
}
f1
=
mul2
<<
add3
assert_kind_of
Proc
,
f1
assert_equal
16
,
f1
.
call
(
5
)
f2
=
mul2
>>
add3
assert_kind_of
Proc
,
f2
assert_equal
13
,
f2
.
call
(
5
)
end
assert
(
'mrb_proc_new_cfunc_with_env'
)
do
ProcExtTest
.
mrb_proc_new_cfunc_with_env
(
:test
)
ProcExtTest
.
mrb_proc_new_cfunc_with_env
(
:mruby
)
...
...
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