Module: Nuggets::Integer::MapMixin

Included in:
Integer
Defined in:
lib/nuggets/integer/map_mixin.rb

Instance Method Summary collapse

Instance Method Details

#map_positiveObject

call-seq:

int.map_positive => anInteger

Creates a bijection from Z to N, i.e., it maps int to a positive integer.



36
37
38
# File 'lib/nuggets/integer/map_mixin.rb', line 36

def map_positive
  2 * abs + (self > 0 ? 0 : 1)
end