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
1e892c0f
Commit
1e892c0f
authored
Nov 25, 2016
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Nov 25, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3280 from bouk/struct-redefine
Remove constant when a struct is redefined.
parents
b4d50175
82731d9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletion
+22
-1
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
+1
-1
mrbgems/mruby-struct/test/struct.rb
mrbgems/mruby-struct/test/struct.rb
+21
-0
No files found.
mrbgems/mruby-struct/src/struct.c
View file @
1e892c0f
...
@@ -203,7 +203,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
...
@@ -203,7 +203,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
}
}
if
(
mrb_const_defined_at
(
mrb
,
mrb_obj_value
(
klass
),
id
))
{
if
(
mrb_const_defined_at
(
mrb
,
mrb_obj_value
(
klass
),
id
))
{
mrb_warn
(
mrb
,
"redefining constant Struct::%S"
,
name
);
mrb_warn
(
mrb
,
"redefining constant Struct::%S"
,
name
);
/* ?rb_mod_remove_const(klass, mrb_sym2name(mrb, id)); */
mrb_const_remove
(
mrb
,
mrb_obj_value
(
klass
),
id
);
}
}
c
=
mrb_define_class_under
(
mrb
,
klass
,
RSTRING_PTR
(
name
),
klass
);
c
=
mrb_define_class_under
(
mrb
,
klass
,
RSTRING_PTR
(
name
),
klass
);
}
}
...
...
mrbgems/mruby-struct/test/struct.rb
View file @
1e892c0f
...
@@ -158,3 +158,24 @@ assert("Struct#dig") do
...
@@ -158,3 +158,24 @@ assert("Struct#dig") do
assert_equal
1
,
a
.
dig
(
:purple
,
:red
)
assert_equal
1
,
a
.
dig
(
:purple
,
:red
)
assert_equal
1
,
a
.
dig
(
1
,
0
)
assert_equal
1
,
a
.
dig
(
1
,
0
)
end
end
assert
(
"Struct.new removes existing constant"
)
do
begin
assert_not_equal
Struct
.
new
(
"Test"
,
:a
),
Struct
.
new
(
"Test"
,
:a
,
:b
)
ensure
Struct
.
remove_const
:Test
end
end
assert
(
"Struct#initialize_copy requires struct to be the same type"
)
do
begin
Struct
.
new
(
"Test"
,
:a
)
a
=
Struct
::
Test
.
new
(
"a"
)
Struct
.
new
(
"Test"
,
:a
,
:b
)
assert_raise
(
TypeError
)
do
a
.
initialize_copy
(
Struct
::
Test
.
new
(
"a"
,
"b"
))
end
ensure
Struct
.
remove_const
:Test
end
end
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