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
c0af0426
Commit
c0af0426
authored
Dec 25, 2012
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #671 from skandhas/pr-add-Module_remove_class_variable
Add Module#remove_class_variable for mruby.
parents
74554e04
3ffe8fe1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
src/class.c
src/class.c
+51
-0
test/t/module.rb
test/t/module.rb
+10
-0
No files found.
src/class.c
View file @
c0af0426
...
...
@@ -1545,6 +1545,56 @@ mrb_mod_cvar_set(mrb_state *mrb, mrb_value mod)
return
value
;
}
/* 15.2.2.4.39 */
/*
* call-seq:
* remove_class_variable(sym) -> obj
*
* Removes the definition of the <i>sym</i>, returning that
* constant's value.
*
* class Dummy
* @@var = 99
* puts @@var
* p class_variables
* remove_class_variable(:@@var)
* p class_variables
* end
*
* <em>produces:</em>
*
* 99
* [:@@var]
* []
*/
mrb_value
mrb_mod_remove_cvar
(
mrb_state
*
mrb
,
mrb_value
mod
)
{
mrb_value
sym
,
val
;
mrb_sym
id
;
mrb_get_args
(
mrb
,
"o"
,
&
sym
);
id
=
mrb_sym_value
(
mrb
,
sym
);
check_cv_name
(
mrb
,
id
);
val
=
mrb_iv_remove
(
mrb
,
mod
,
id
);
if
(
!
mrb_undef_p
(
val
))
return
val
;
if
(
mrb_cv_defined
(
mrb
,
mod
,
id
)){
mrb_name_error
(
mrb
,
id
,
"cannot remove %s for %s"
,
mrb_sym2name
(
mrb
,
id
),
mrb_class_name
(
mrb
,
mrb_class_ptr
(
mod
)));
}
mrb_name_error
(
mrb
,
id
,
"class variable %s not defined for %s"
,
mrb_sym2name
(
mrb
,
id
),
mrb_class_name
(
mrb
,
mrb_class_ptr
(
mod
)));
/* not reached */
return
mrb_nil_value
();
}
static
void
check_const_name
(
mrb_state
*
mrb
,
mrb_sym
id
)
{
...
...
@@ -1659,6 +1709,7 @@ mrb_init_class(mrb_state *mrb)
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
,
"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
,
"to_s"
,
mrb_mod_to_s
,
ARGS_NONE
());
mrb_define_method
(
mrb
,
mod
,
"inspect"
,
mrb_mod_to_s
,
ARGS_NONE
());
...
...
test/t/module.rb
View file @
c0af0426
...
...
@@ -208,6 +208,16 @@ assert('Module#module_eval', '15.2.2.4.35') do
Test4ModuleEval
.
module_eval
{
@b
}
==
12
end
assert
(
'Module#remove_class_variable'
,
'15.2.2.4.39'
)
do
class
Test4RemoveClassVariable
@@cv
=
99
end
Test4RemoveClassVariable
.
remove_class_variable
(
:@@cv
)
==
99
and
not
Test4RemoveClassVariable
.
class_variables
.
include?
:@@cv
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