Sha256: 47ee59d6a53b74b4a53327360e62818f1749fe41ea794ba15bad11084cb82e48

Contents?: true

Size: 506 Bytes

Versions: 12

Compression:

Stored size: 506 Bytes

Contents

class Range
  def limit(value)
    if value < first then first
    elsif value > last then last
    else value
    end
  end
end

class Numeric
  def limit(range)
    range.limit(self)
  end
end

module Range::Etest
  def test_range
    assert_equal 1, (1..3).limit(-1)
    assert_equal 1, (1..3).limit(1)
    assert_equal 2, (1..3).limit(2)
    assert_equal 3, (1..3).limit(3)
    assert_equal 3, (1..3).limit(4)
  end

  def test_numeric
    assert_equal 1, -1.limit(1..3)
  end
end if VEX_TEST == "base"

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vex-0.6.2 lib/vex/base/range_ext.rb
vex-0.4.4 lib/vex/base/range_ext.rb
vex-0.4.2 lib/vex/base/range_ext.rb
vex-0.3.3 lib/vex/base/range_ext.rb
vex-0.2.9 lib/vex/base/range_ext.rb
vex-0.2.8 lib/vex/base/range_ext.rb
vex-0.2.7 lib/vex/base/range_ext.rb
vex-0.2.6 lib/vex/base/range_ext.rb
vex-0.2.5 lib/vex/base/range_ext.rb
vex-0.2.2 lib/vex/base/range_ext.rb
vex-0.2.1 lib/vex/base/range_ext.rb
vex-0.2 lib/vex/base/range_ext.rb