Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 97c331d2a7b7
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cdb05eafb63e
Choose a head ref
  • 19 commits
  • 4 files changed
  • 2 contributors

Commits on Jun 13, 2015

  1. Adds Numeric#step keyword arguments specs.

    The implementation moves the specs that applies to all modes
    (positional arguments, keyword arguments and mixed arguments) to a
    shared spec file.
    The specific code is maintained on the main Numeric#step spec file.
    fmfdias committed Jun 13, 2015
    Copy the full SHA
    0c056f2 View commit details
  2. Copy the full SHA
    bf2d9cd View commit details
  3. Copy the full SHA
    d6ad6c3 View commit details
  4. Copy the full SHA
    e6f251a View commit details
  5. Copy the full SHA
    83eb732 View commit details
  6. Copy the full SHA
    7a2f858 View commit details
  7. Copy the full SHA
    0e2be45 View commit details
  8. Copy the full SHA
    c2f4895 View commit details
  9. Copy the full SHA
    b212953 View commit details
  10. Copy the full SHA
    fde6a01 View commit details
  11. Use value instead of self.

    When one the params is a float, the results are floats.
    fmfdias committed Jun 13, 2015
    Copy the full SHA
    3f39c32 View commit details
  12. Copy the full SHA
    469b904 View commit details
  13. Remove ruby_bug guards

    fmfdias committed Jun 13, 2015
    Copy the full SHA
    51a278b View commit details
  14. Copy the full SHA
    c9068fc View commit details
  15. Copy the full SHA
    9aec8f8 View commit details
  16. Improve shared spec comment.

    fmfdias committed Jun 13, 2015
    Copy the full SHA
    02ad34c View commit details
  17. Copy the full SHA
    bd606b5 View commit details

Commits on Apr 6, 2016

  1. Merge branch 'add_numeric_step_kw_args' of https://github.com/fmfdias…

    …/rubinius into fmfdias-add_numeric_step_kw_args
    brixen committed Apr 6, 2016
    Copy the full SHA
    20ff1eb View commit details
  2. Copy the full SHA
    cdb05ea View commit details
Showing with 500 additions and 371 deletions.
  1. +10 −6 core/numeric.rb
  2. +9 −3 core/numeric_mirror.rb
  3. +390 −0 spec/ruby/core/numeric/shared/step.rb
  4. +91 −362 spec/ruby/core/numeric/step_spec.rb
16 changes: 10 additions & 6 deletions core/numeric.rb
Original file line number Diff line number Diff line change
@@ -31,23 +31,27 @@ def <=>(other)
return nil
end

def step(limit, step=1)
def step(limit=nil, step=nil, to: nil, by: nil)
unless block_given?
return to_enum(:step, limit, step) do
Rubinius::Mirror::Numeric.reflect(self).step_size(limit, step)
return to_enum(:step, limit, step, to: to, by: by) do
Rubinius::Mirror::Numeric.reflect(self).step_size(limit, step, to, by)
end
end

raise ArgumentError, "step cannot be 0" if step == 0

m = Rubinius::Mirror::Numeric.reflect(self)
values = m.step_fetch_args(limit, step)
values = m.step_fetch_args(limit, step, to, by)
value = values[0]
limit = values[1]
step = values[2]
asc = values[3]
is_float = values[4]

if step == 0
while true
yield value
end
end

if is_float
n = m.step_float_size(value, limit, step, asc)

12 changes: 9 additions & 3 deletions core/numeric_mirror.rb
Original file line number Diff line number Diff line change
@@ -21,14 +21,16 @@ def step_float_size(value, limit, step, asc)
end
end

def step_size(limit, step)
values = step_fetch_args(limit, step)
def step_size(limit, step, to, by)
values = step_fetch_args(limit, step, to, by)
value = values[0]
limit = values[1]
step = values[2]
asc = values[3]
is_float = values[4]

return Float::INFINITY if step == 0

if is_float
# Ported from MRI

@@ -43,9 +45,13 @@ def step_size(limit, step)
end
end

def step_fetch_args(limit, step)
def step_fetch_args(limit, step, to, by)
raise ArgumentError, "limit is given twice" if limit && to
raise ArgumentError, "step is given twice" if step && by
raise ArgumentError, "step cannot be 0" if step == 0

limit ||= to
step ||= by || 1
value = @object
asc = step > 0
if value.kind_of? Float or limit.kind_of? Float or step.kind_of? Float
Loading