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
48ac1f74
Commit
48ac1f74
authored
May 10, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2218 from take-cheeze/move_method
Move `__method__` to mruby-kernel-ext since it's not ISO method.
parents
64b30b65
d0c0beb8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
35 deletions
+35
-35
mrbgems/mruby-kernel-ext/src/kernel.c
mrbgems/mruby-kernel-ext/src/kernel.c
+21
-0
mrbgems/mruby-kernel-ext/test/kernel.rb
mrbgems/mruby-kernel-ext/test/kernel.rb
+14
-0
src/kernel.c
src/kernel.c
+0
-21
test/t/kernel.rb
test/t/kernel.rb
+0
-14
No files found.
mrbgems/mruby-kernel-ext/src/kernel.c
View file @
48ac1f74
#include "mruby.h"
#include "mruby/error.h"
/*
* call-seq:
* __method__ -> symbol
*
* Returns the name at the definition of the current method as a
* Symbol.
* If called outside of a method, it returns <code>nil</code>.
*
*/
static
mrb_value
mrb_f_method
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_callinfo
*
ci
=
mrb
->
c
->
ci
;
ci
--
;
if
(
ci
->
mid
)
return
mrb_symbol_value
(
ci
->
mid
);
else
return
mrb_nil_value
();
}
void
mrb_mruby_kernel_ext_gem_init
(
mrb_state
*
mrb
)
{
struct
RClass
*
krn
=
mrb
->
kernel_module
;
mrb_define_module_function
(
mrb
,
krn
,
"fail"
,
mrb_f_raise
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
krn
,
"__method__"
,
mrb_f_method
,
MRB_ARGS_NONE
());
}
void
...
...
mrbgems/mruby-kernel-ext/test/kernel.rb
View file @
48ac1f74
...
...
@@ -2,3 +2,17 @@ assert('Kernel.fail, Kernel#fail') do
assert_raise
(
RuntimeError
)
{
fail
}
assert_raise
(
RuntimeError
)
{
Kernel
.
fail
}
end
assert
(
'Kernel#__method__'
)
do
assert_equal
(
:m
,
Class
.
new
{
def
m
;
__method__
;
end
}.
new
.
m
)
assert_equal
(
:m
,
Class
.
new
{
define_method
(
:m
)
{
__method__
}}.
new
.
m
)
c
=
Class
.
new
do
[
:m1
,
:m2
].
each
do
|
m
|
define_method
(
m
)
do
__method__
end
end
end
assert_equal
(
:m1
,
c
.
new
.
m1
)
assert_equal
(
:m2
,
c
.
new
.
m2
)
end
src/kernel.c
View file @
48ac1f74
...
...
@@ -210,26 +210,6 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
return
mrb_bool_value
(
given_p
);
}
/*
* call-seq:
* __method__ -> symbol
*
* Returns the name at the definition of the current method as a
* Symbol.
* If called outside of a method, it returns <code>nil</code>.
*
*/
static
mrb_value
mrb_f_method
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_callinfo
*
ci
=
mrb
->
c
->
ci
;
ci
--
;
if
(
ci
->
mid
)
return
mrb_symbol_value
(
ci
->
mid
);
else
return
mrb_nil_value
();
}
/* 15.3.1.3.7 */
/*
* call-seq:
...
...
@@ -1153,7 +1133,6 @@ mrb_init_kernel(mrb_state *mrb)
mrb_define_method
(
mrb
,
krn
,
"==="
,
mrb_equal_m
,
MRB_ARGS_REQ
(
1
));
/* 15.3.1.3.2 */
mrb_define_method
(
mrb
,
krn
,
"__id__"
,
mrb_obj_id_m
,
MRB_ARGS_NONE
());
/* 15.3.1.3.3 */
mrb_define_method
(
mrb
,
krn
,
"__send__"
,
mrb_f_send
,
MRB_ARGS_ANY
());
/* 15.3.1.3.4 */
mrb_define_method
(
mrb
,
krn
,
"__method__"
,
mrb_f_method
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
krn
,
"block_given?"
,
mrb_f_block_given_p_m
,
MRB_ARGS_NONE
());
/* 15.3.1.3.6 */
mrb_define_method
(
mrb
,
krn
,
"class"
,
mrb_obj_class_m
,
MRB_ARGS_NONE
());
/* 15.3.1.3.7 */
mrb_define_method
(
mrb
,
krn
,
"clone"
,
mrb_obj_clone
,
MRB_ARGS_NONE
());
/* 15.3.1.3.8 */
...
...
test/t/kernel.rb
View file @
48ac1f74
...
...
@@ -528,20 +528,6 @@ assert('Kernel#global_variables') do
end
end
assert
(
'Kernel#__method__'
)
do
assert_equal
(
:m
,
Class
.
new
{
def
m
;
__method__
;
end
}.
new
.
m
)
assert_equal
(
:m
,
Class
.
new
{
define_method
(
:m
)
{
__method__
}}.
new
.
m
)
c
=
Class
.
new
do
[
:m1
,
:m2
].
each
do
|
m
|
define_method
(
m
)
do
__method__
end
end
end
assert_equal
(
:m1
,
c
.
new
.
m1
)
assert_equal
(
:m2
,
c
.
new
.
m2
)
end
assert
(
'Kernel#define_singleton_method'
)
do
o
=
Object
.
new
ret
=
o
.
define_singleton_method
(
:test_method
)
do
...
...
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