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
db2fed84
Commit
db2fed84
authored
Jan 04, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #686 from skandhas/pr-add-Module-method_defined
Add Module#method_defined? for mruby
parents
5df3a9db
c4995884
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
src/class.c
src/class.c
+43
-0
test/t/module.rb
test/t/module.rb
+24
-0
No files found.
src/class.c
View file @
db2fed84
...
...
@@ -1595,6 +1595,48 @@ mrb_mod_remove_cvar(mrb_state *mrb, mrb_value mod)
return
mrb_nil_value
();
}
/* 15.2.2.4.34 */
/*
* call-seq:
* mod.method_defined?(symbol) -> true or false
*
* Returns +true+ if the named method is defined by
* _mod_ (or its included modules and, if _mod_ is a class,
* its ancestors). Public and protected methods are matched.
*
* module A
* def method1() end
* end
* class B
* def method2() end
* end
* class C < B
* include A
* def method3() end
* end
*
* A.method_defined? :method1 #=> true
* C.method_defined? "method1" #=> true
* C.method_defined? "method2" #=> true
* C.method_defined? "method3" #=> true
* C.method_defined? "method4" #=> false
*/
static
mrb_value
mrb_mod_method_defined
(
mrb_state
*
mrb
,
mrb_value
mod
)
{
mrb_value
sym
;
mrb_sym
id
;
mrb_get_args
(
mrb
,
"o"
,
&
sym
);
id
=
mrb_sym_value
(
mrb
,
sym
);
if
(
mrb_obj_respond_to
(
mrb_class_ptr
(
mod
),
id
))
{
return
mrb_true_value
();
}
return
mrb_false_value
();
}
static
void
remove_method
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
mrb_sym
mid
)
{
...
...
@@ -1750,6 +1792,7 @@ mrb_init_class(mrb_state *mrb)
mrb_define_method
(
mrb
,
mod
,
"included"
,
mrb_bob_init
,
ARGS_REQ
(
1
));
/* 15.2.2.4.29 */
mrb_define_method
(
mrb
,
mod
,
"included_modules"
,
mrb_mod_included_modules
,
ARGS_NONE
());
/* 15.2.2.4.30 */
mrb_define_method
(
mrb
,
mod
,
"instance_methods"
,
mrb_mod_instance_methods
,
ARGS_ANY
());
/* 15.2.2.4.33 */
mrb_define_method
(
mrb
,
mod
,
"method_defined?"
,
mrb_mod_method_defined
,
ARGS_REQ
(
1
));
/* 15.2.2.4.34 */
mrb_define_method
(
mrb
,
mod
,
"module_eval"
,
mrb_mod_module_eval
,
ARGS_ANY
());
/* 15.2.2.4.35 */
mrb_define_method
(
mrb
,
mod
,
"remove_class_variable"
,
mrb_mod_remove_cvar
,
ARGS_REQ
(
1
));
/* 15.2.2.4.39 */
mrb_define_method
(
mrb
,
mod
,
"remove_method"
,
mrb_mod_remove_method
,
ARGS_ANY
());
/* 15.2.2.4.41 */
...
...
test/t/module.rb
View file @
db2fed84
...
...
@@ -199,6 +199,30 @@ assert('Module#instance_methods', '15.2.2.4.33') do
r
.
class
==
Array
and
r
.
include?
(
:method3
)
and
r
.
include?
(
:method2
)
end
assert
(
'Module#method_defined?'
,
'15.2.2.4.34'
)
do
module
Test4MethodDefined
module
A
def
method1
()
end
end
class
B
def
method2
()
end
end
class
C
<
B
include
A
def
method3
()
end
end
end
Test4MethodDefined
::
A
.
method_defined?
:method1
and
Test4MethodDefined
::
C
.
method_defined?
:method1
and
Test4MethodDefined
::
C
.
method_defined?
"method2"
and
Test4MethodDefined
::
C
.
method_defined?
"method3"
and
not
Test4MethodDefined
::
C
.
method_defined?
"method4"
end
assert
(
'Module#module_eval'
,
'15.2.2.4.35'
)
do
module
Test4ModuleEval
@a
=
11
...
...
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