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



172
173
174
# File 'lib/puppet/pops/types/types.rb', line 172

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)



158
159
160
161
162
163
164
165
166
# File 'lib/puppet/pops/types/types.rb', line 158

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



168
169
170
# File 'lib/puppet/pops/types/types.rb', line 168

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.



146
147
148
149
150
151
152
153
154
# File 'lib/puppet/pops/types/types.rb', line 146

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

#sizeObject

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



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

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