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
dd149736
Commit
dd149736
authored
Nov 26, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2655 from tmtm/fix-numeric-step
Fix: Numeric#step infinite loop.
parents
1365151d
bbab89e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
mrblib/numeric.rb
mrblib/numeric.rb
+11
-3
No files found.
mrblib/numeric.rb
View file @
dd149736
...
@@ -101,12 +101,20 @@ module Integral
...
@@ -101,12 +101,20 @@ module Integral
# incremented by +step+ (default 1).
# incremented by +step+ (default 1).
#
#
def
step
(
num
,
step
=
1
,
&
block
)
def
step
(
num
,
step
=
1
,
&
block
)
raise
ArgumentError
,
"step can't be 0"
if
step
==
0
return
to_enum
(
:step
,
num
,
step
)
unless
block_given?
return
to_enum
(
:step
,
num
,
step
)
unless
block_given?
i
=
if
num
.
kind_of?
Float
then
self
.
to_f
else
self
end
i
=
if
num
.
kind_of?
Float
then
self
.
to_f
else
self
end
while
(
i
<=
num
)
if
step
>
0
block
.
call
(
i
)
while
(
i
<=
num
)
i
+=
step
block
.
call
(
i
)
i
+=
step
end
else
while
(
i
>=
num
)
block
.
call
(
i
)
i
+=
step
end
end
end
self
self
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