Module: Puppet::Pops::Types::PIntegerType::ClassModule

Includes:
Enumerable
Defined in:
lib/puppet/pops/types/types.rb

Instance Method Summary collapse

Instance Method Details

#==(o) ⇒ Object



143
144
145
# File 'lib/puppet/pops/types/types.rb', line 143

def ==(o)
  self.class == o.class && from == o.from && to == o.to
end

#eachObject

Returns Enumerator if no block is given Returns self if size is infinity (does not yield)



129
130
131
132
133
134
135
136
137
# File 'lib/puppet/pops/types/types.rb', line 129

def each
  return self.to_enum unless block_given?
  return nil if from.nil? || to.nil?
  if to < from
    from.downto(to) {|x| yield x }
  else
    from.upto(to) {|x| yield x }
  end
end

#hashObject



139
140
141
# File 'lib/puppet/pops/types/types.rb', line 139

def hash
  [self.class, from, to].hash
end

#rangeObject

Returns the range as an array ordered so the smaller number is always first. The number may be Infinity or -Infinity.



117
118
119
120
121
122
123
124
125
# File 'lib/puppet/pops/types/types.rb', line 117

def range
  f = from || -Float::INFINITY
  t = to || Float::INFINITY
  if f < t
    [f, t]
  else
    [t,f]
  end
end

#sizeObject

Returns Float.Infinity if one end of the range is unbound



110
111
112
113
# File 'lib/puppet/pops/types/types.rb', line 110

def size
  return Float::INFINITY if from.nil? || to.nil?
  1+(to-from).abs
end