class XRange

Public Instance Methods

==(other) click to toggle source
# File lib/primitive_wrapper.rb, line 1002
def ==(other)
  @value.eql? (~other)
end
===(other) click to toggle source
# File lib/primitive_wrapper.rb, line 998
def ===(other)
  @value.include? other
end
count() click to toggle source
# File lib/primitive_wrapper.rb, line 973
def count
  size
end
cover?(val) click to toggle source
# File lib/primitive_wrapper.rb, line 979
def cover?(val)  # means val>=start and val<=end ... different than include
  @value.reorder.include? val
end
each(&block) click to toggle source
# File lib/primitive_wrapper.rb, line 1076
def each(&block)
  self.send(:step, 1, &block)
end
eql?() click to toggle source
# File lib/primitive_wrapper.rb, line 995
def eql?
  @value.eql? (~other)
end
include?(val) click to toggle source
# File lib/primitive_wrapper.rb, line 976
def include?(val)  # account for reversed ordering
  @value.reorder.include? val
end
max(*n, &block) click to toggle source
# File lib/primitive_wrapper.rb, line 989
def max(*n, &block)
  @value.reorder.send(:max, *n, &block)  
end
member?(val) click to toggle source
# File lib/primitive_wrapper.rb, line 982
def member?(val) # same as include?
  @value.reorder.include? val
end
min(*n, &block) click to toggle source
# File lib/primitive_wrapper.rb, line 992
def min(*n, &block)
  @value.reorder.send(:min, *n, &block)  
end
re_range(ng) click to toggle source
# File lib/primitive_wrapper.rb, line 924
def re_range(ng) 
  return self if ng.nil?
  return self if ng <= 0
  return self unless first.kind_of? Integer    
  t_first = first
  t_last = last
  if first.negative?
    t_first = ng+first
  end
  if last.negative?
    t_last = ng+last
  end
  if exclude_end?
    XRange.new (t_first...t_last)
  else
    XRange.new (t_first..t_last)
  end
end
re_range!(ng) click to toggle source
# File lib/primitive_wrapper.rb, line 942
def re_range!(ng)
  replace re_range(ng)
end
reorder!() click to toggle source
# File lib/primitive_wrapper.rb, line 907
def reorder!
  @value = @value.reorder
  self
end
reverse() click to toggle source
# File lib/primitive_wrapper.rb, line 904
def reverse
  @value.reverse.to_xr
end
reverse!() click to toggle source
# File lib/primitive_wrapper.rb, line 900
def reverse!
  @value = @value.reverse
  self
end
reverse_each(&block) click to toggle source
# File lib/primitive_wrapper.rb, line 1080
def reverse_each(&block)
  self.send(:reverse_step, 1, &block)
end
reverse_step(n=1) { |curr| ... } click to toggle source
# File lib/primitive_wrapper.rb, line 1041
def reverse_step(n=1)
  n = 1 if n<= 0
  return Enumerator.enumerate_yields(self, :reverse_step, n) unless block_given?
  curr = last.pw_copy
  if exclude_end?
    if reversed?
      loop do
        break if curr >= first
        yield curr
        n.times { |t| curr = curr.succ }
      end
    else
      loop do
        break if curr <= first
        yield curr
        n.times { |t| curr = curr.pred }
      end
    end
  else
    if reversed?
      loop do
        yield curr
        break if curr >= first
        n.times { |t| curr = curr.succ }
      end
    else
      loop do
        yield curr
        break if curr <= first
        n.times { |t| curr = curr.pred }
      end
    end
  end    
end
simplify() click to toggle source
# File lib/primitive_wrapper.rb, line 915
def simplify
  @value.simplify.to_xr
end
simplify!() click to toggle source
# File lib/primitive_wrapper.rb, line 911
def simplify!
  @value = @value.simplify
  self
end
size() click to toggle source
# File lib/primitive_wrapper.rb, line 945
def size   # getting the wrong count ... off by 1
  dirty = false
  sz = @value.size
  if sz.nil?
    dirty = true
  elsif sz==0
    dirty = true
  end
  unless dirty
    return sz
  end
  if first.respond_to? :lcm  # Covers both Integer and Int
    sz = reversed? ? @value.reverse.size : @value.size
    return sz
  end
  range = @value.reorder
  cnt = 0
  # curr = range.first.dup rescue range.first
  curr = range.first.pw_copy
  stop = range.last
  loop do
    cnt += 1  # 5..5 is count of 1
    break if curr==stop
    curr.succ!
  end
  cnt -= 1 if exclude_end?
  return cnt  
end
step(n=1) { |curr| ... } click to toggle source
# File lib/primitive_wrapper.rb, line 1006
def step(n=1)
  n = 1 if n<= 0
  return Enumerator.enumerate_yields(self, :step, n) unless block_given?
  curr = first.pw_copy
  if exclude_end?
    if reversed?
      loop do
        break if curr <= last
        yield curr
        n.times { |t| curr = curr.pred }
      end
    else
      loop do
        break if curr >= last
        yield curr
        n.times { |t| curr = curr.succ }
      end
    end
  else
    if reversed?
      loop do
        yield curr
        break if curr <= last
        n.times { |t| curr = curr.pred }
      end
    else
      loop do
        yield curr
        break if curr >= last
        n.times { |t| curr = curr.succ }
      end
    end
  end    
end
to_a() click to toggle source
# File lib/primitive_wrapper.rb, line 985
def to_a
  dat = @value.reorder.to_a
  return reversed? ? dat.reverse : dat    
end
to_range() click to toggle source
# File lib/primitive_wrapper.rb, line 921
def to_range  # add similar to other wrappers
  @value
end
to_xr() click to toggle source
# File lib/primitive_wrapper.rb, line 918
def to_xr
  self
end
valid_type(prm) click to toggle source
# File lib/primitive_wrapper.rb, line 895
def valid_type(prm)
  return true if prm.kind_of? Range
  return true if prm.kind_of? XRange
  false
end