Module: VV::IntegerMethods

Included in:
Integer
Defined in:
lib/vv/integer_methods.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/vv/integer_methods.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#characters(character, fail_on_negative: false) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/vv/integer_methods.rb', line 24

def characters character, fail_on_negative: false
  message = "Expected single character, not #{character}."
  fail ArgumentError, message if character.length > 1

  message = "Expected non-negative integer, not `#{self}`."
  fail message if self < 0 and fail_on_negative

  ( self > 0 ) ? ( character * self ) : String.empty_string
end

#dashesObject



20
21
22
# File 'lib/vv/integer_methods.rb', line 20

def dashes
  characters String.dash
end

#spacesObject



16
17
18
# File 'lib/vv/integer_methods.rb', line 16

def spaces
  characters String.space
end

#to_i!Object



34
35
36
# File 'lib/vv/integer_methods.rb', line 34

def to_i!
  self
end