Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/andy_convenience.rb

Instance Method Summary collapse

Instance Method Details

#increment(interval = 1, operator = :+, seq = 1) ⇒ Object Also known as: inc



57
58
59
60
61
# File 'lib/andy_convenience.rb', line 57

def increment(interval = 1, operator = :+, seq = 1)
  int = self
  seq.times { int = int.send(operator.to_sym, interval) }
  int
end

#stringcrement(interval = 1, operator = :+, seq = 1) ⇒ Object Also known as: strc



63
64
65
# File 'lib/andy_convenience.rb', line 63

def stringcrement(interval = 1, operator = :+, seq = 1)
  self.increment(interval, operator, seq).to_s
end

#to_binaryObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/andy_convenience.rb', line 71

def to_binary
  final_string = ''
  bins = binlib.select { |n| n <= self }.reverse
  return '0' if bins.empty?
  return '1' if bins[0] == 1
  final_string << '1'
  difference = self - bins[0]
  bins[1..-1].each do |bin|
    if difference >= bin
      final_string << '1'
      difference -= bin
    else
      final_string << '0'
    end
  end
  final_string
end

#to_tknObject



67
68
69
# File 'lib/andy_convenience.rb', line 67

def to_tkn
  SecureRandom.urlsafe_base64(self)
end