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
48903850
Commit
48903850
authored
May 23, 2019
by
KOBAYASHI Shuji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Freeze `Rational` and `Complex` objects
parent
5f4eb877
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
1 deletion
+15
-1
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
+1
-0
mrbgems/mruby-complex/test/complex.rb
mrbgems/mruby-complex/test/complex.rb
+7
-1
mrbgems/mruby-rational/src/rational.c
mrbgems/mruby-rational/src/rational.c
+1
-0
mrbgems/mruby-rational/test/rational.rb
mrbgems/mruby-rational/test/rational.rb
+6
-0
No files found.
mrbgems/mruby-complex/src/complex.c
View file @
48903850
...
@@ -24,6 +24,7 @@ complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
...
@@ -24,6 +24,7 @@ complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
struct
mrb_complex
*
p
=
complex_ptr
(
mrb
,
comp
);
struct
mrb_complex
*
p
=
complex_ptr
(
mrb
,
comp
);
p
->
real
=
real
;
p
->
real
=
real
;
p
->
imaginary
=
imaginary
;
p
->
imaginary
=
imaginary
;
MRB_SET_FROZEN_FLAG
(
s
);
return
comp
;
return
comp
;
}
}
...
...
mrbgems/mruby-complex/test/complex.rb
View file @
48903850
...
@@ -126,3 +126,9 @@ assert 'Complex::to_i' do
...
@@ -126,3 +126,9 @@ assert 'Complex::to_i' do
Complex
(
1
,
2
).
to_i
Complex
(
1
,
2
).
to_i
end
end
end
end
assert
'Complex#frozen?'
do
assert_predicate
(
1
i
,
:frozen?
)
assert_predicate
(
Complex
(
2
,
3
),
:frozen?
)
assert_predicate
(
4
+
5
i
,
:frozen?
)
end
mrbgems/mruby-rational/src/rational.c
View file @
48903850
...
@@ -37,6 +37,7 @@ rational_new(mrb_state *mrb, mrb_int numerator, mrb_int denominator)
...
@@ -37,6 +37,7 @@ rational_new(mrb_state *mrb, mrb_int numerator, mrb_int denominator)
struct
mrb_rational
*
p
=
rational_ptr
(
rat
);
struct
mrb_rational
*
p
=
rational_ptr
(
rat
);
p
->
numerator
=
numerator
;
p
->
numerator
=
numerator
;
p
->
denominator
=
denominator
;
p
->
denominator
=
denominator
;
MRB_SET_FROZEN_FLAG
(
s
);
return
rat
;
return
rat
;
}
}
...
...
mrbgems/mruby-rational/test/rational.rb
View file @
48903850
...
@@ -278,3 +278,9 @@ assert 'Rational#negative?' do
...
@@ -278,3 +278,9 @@ assert 'Rational#negative?' do
assert_not_predicate
(
Rational
(
2
,
3
),
:negative?
)
assert_not_predicate
(
Rational
(
2
,
3
),
:negative?
)
assert_not_predicate
(
Rational
(
0
),
:negative?
)
assert_not_predicate
(
Rational
(
0
),
:negative?
)
end
end
assert
'Rational#frozen?'
do
assert_predicate
(
1
r
,
:frozen?
)
assert_predicate
(
Rational
(
2
,
3
),
:frozen?
)
assert_predicate
(
4
/
5
r
,
:frozen?
)
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