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
2ea245db
Commit
2ea245db
authored
Nov 26, 2012
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #572 from skandhas/pr-add-Module-instance_methods
add "Module#instance_methods" for mruby
parents
d03bd87d
1f3c5125
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
1 deletion
+63
-1
src/class.c
src/class.c
+42
-0
src/kernel.c
src/kernel.c
+1
-1
test/t/module.rb
test/t/module.rb
+20
-0
No files found.
src/class.c
View file @
2ea245db
...
...
@@ -807,6 +807,47 @@ mrb_mod_included_modules(mrb_state *mrb, mrb_value self)
return
result
;
}
mrb_value
class_instance_method_list
(
mrb_state
*
,
int
,
mrb_value
*
,
struct
RClass
*
,
int
);
/* 15.2.2.4.33 */
/*
* call-seq:
* mod.instance_methods(include_super=true) -> array
*
* Returns an array containing the names of the public and protected instance
* methods in the receiver. For a module, these are the public and protected methods;
* for a class, they are the instance (not singleton) methods. With no
* argument, or with an argument that is <code>false</code>, the
* instance methods in <i>mod</i> are returned, otherwise the methods
* in <i>mod</i> and <i>mod</i>'s superclasses are returned.
*
* module A
* def method1() end
* end
* class B
* def method2() end
* end
* class C < B
* def method3() end
* end
*
* A.instance_methods #=> [:method1]
* B.instance_methods(false) #=> [:method2]
* C.instance_methods(false) #=> [:method3]
* C.instance_methods(true).length #=> 43
*/
static
mrb_value
mrb_mod_instance_methods
(
mrb_state
*
mrb
,
mrb_value
mod
)
{
mrb_value
*
argv
;
int
argc
;
struct
RClass
*
c
=
mrb_class_ptr
(
mod
);
mrb_get_args
(
mrb
,
"*"
,
&
argv
,
&
argc
);
return
class_instance_method_list
(
mrb
,
argc
,
argv
,
c
,
0
);
}
mrb_value
mrb_singleton_class
(
mrb_state
*
mrb
,
mrb_value
v
)
{
...
...
@@ -1465,6 +1506,7 @@ mrb_init_class(mrb_state *mrb)
mrb_define_method
(
mrb
,
mod
,
"append_features"
,
mrb_mod_append_features
,
ARGS_REQ
(
1
));
/* 15.2.2.4.10 */
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
,
"to_s"
,
mrb_mod_to_s
,
ARGS_NONE
());
mrb_define_method
(
mrb
,
mod
,
"inspect"
,
mrb_mod_to_s
,
ARGS_NONE
());
...
...
src/kernel.c
View file @
2ea245db
...
...
@@ -717,7 +717,7 @@ method_entry_loop(mrb_state *mrb, struct RClass* klass, mrb_value ary)
}
}
static
mrb_value
mrb_value
class_instance_method_list
(
mrb_state
*
mrb
,
int
argc
,
mrb_value
*
argv
,
struct
RClass
*
klass
,
int
obj
)
{
mrb_value
ary
;
...
...
test/t/module.rb
View file @
2ea245db
...
...
@@ -132,6 +132,26 @@ assert('Module#included_modules', '15.2.2.4.30') do
r
.
class
==
Array
and
r
.
include?
(
Test4includedModules
)
end
assert
(
'Module#instance_methods'
,
'15.2.2.4.33'
)
do
module
Test4InstanceMethodsA
def
method1
()
end
end
class
Test4InstanceMethodsB
def
method2
()
end
end
class
Test4InstanceMethodsC
<
Test4InstanceMethodsB
def
method3
()
end
end
r
=
Test4InstanceMethodsC
.
instance_methods
(
true
)
Test4InstanceMethodsA
.
instance_methods
==
[
:method1
]
and
Test4InstanceMethodsB
.
instance_methods
(
false
)
==
[
:method2
]
and
Test4InstanceMethodsC
.
instance_methods
(
false
)
==
[
:method3
]
and
r
.
class
==
Array
and
r
.
include?
(
:method3
)
and
r
.
include?
(
:method2
)
end
# Not ISO specified
assert
(
'Module#to_s'
)
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