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
b69bb896
Commit
b69bb896
authored
Jan 25, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1664 from h2so5/clone-class-module
clone Class/Module rightly
parents
e0e5aebc
25045345
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
2 deletions
+36
-2
src/kernel.c
src/kernel.c
+12
-2
test/t/class.rb
test/t/class.rb
+10
-0
test/t/module.rb
test/t/module.rb
+14
-0
No files found.
src/kernel.c
View file @
b69bb896
...
...
@@ -293,13 +293,23 @@ mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj)
}
}
static
void
copy_class
(
mrb_state
*
mrb
,
mrb_value
dst
,
mrb_value
src
)
{
struct
RClass
*
dc
=
mrb_class_ptr
(
dst
);
struct
RClass
*
sc
=
mrb_class_ptr
(
src
);
dc
->
mt
=
kh_copy
(
mt
,
mrb
,
sc
->
mt
);
dc
->
super
=
sc
->
super
;
}
static
void
init_copy
(
mrb_state
*
mrb
,
mrb_value
dest
,
mrb_value
obj
)
{
switch
(
mrb_type
(
obj
))
{
case
MRB_TT_OBJECT
:
switch
(
mrb_type
(
obj
))
{
case
MRB_TT_CLASS
:
case
MRB_TT_MODULE
:
copy_class
(
mrb
,
dest
,
obj
);
case
MRB_TT_OBJECT
:
case
MRB_TT_SCLASS
:
case
MRB_TT_HASH
:
case
MRB_TT_DATA
:
...
...
test/t/class.rb
View file @
b69bb896
...
...
@@ -359,3 +359,13 @@ assert('singleton tests') do
end
end
end
assert
(
'clone Class'
)
do
class
Foo
def
func
true
end
end
Foo
.
clone
.
new
.
func
end
test/t/module.rb
View file @
b69bb896
...
...
@@ -503,3 +503,17 @@ assert('Issue 1467') do
C1
.
new
C2
.
new
end
assert
(
'clone Module'
)
do
module
M1
def
foo
true
end
end
class
B
include
M1
.
clone
end
B
.
new
.
foo
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