Module: VV::ArrayMethods
- Included in:
- Array
- Defined in:
- lib/vv/array_methods.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #cli_print(width: 80, padding: 0, position: 0, separator: nil) ⇒ Object
- #eighth ⇒ Object
- #fifth ⇒ Object
- #format!(other) ⇒ Object
- #fourth ⇒ Object
- #ninth ⇒ Object
- #second ⇒ Object
- #seventh ⇒ Object
- #sixth ⇒ Object
- #spaced ⇒ Object
- #tenth ⇒ Object
- #third ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 |
# File 'lib/vv/array_methods.rb', line 4 def self.included(base) base.extend(ClassMethods) base.include(VV::SetMethods::SetAndArrayMethods) base.attr_accessor :cli_print_separator end |
Instance Method Details
#cli_print(width: 80, padding: 0, position: 0, separator: nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/vv/array_methods.rb', line 62 def cli_print width: 80, padding: 0, position: 0, separator: nil @cli_print_separator ||= String.space separator ||= @cli_print_separator pad_length = padding - position position += pad_length print pad_length.spaces separator_required = false self.each do | elem | printable = String.capture_stdout { elem.cli_print width: width, padding: padding, position: position } string = printable.dup string.prepend separator if separator_required delta = string.unstyled.length if position + delta > width puts print padding.spaces print printable position = padding + printable.unstyled.length else print string position += delta end separator_required = true end position end |
#eighth ⇒ Object
50 51 52 |
# File 'lib/vv/array_methods.rb', line 50 def eighth self[7] end |
#fifth ⇒ Object
38 39 40 |
# File 'lib/vv/array_methods.rb', line 38 def fifth self[4] end |
#format!(other) ⇒ Object
22 23 24 |
# File 'lib/vv/array_methods.rb', line 22 def format!(other) self.spaced.format! other end |
#fourth ⇒ Object
34 35 36 |
# File 'lib/vv/array_methods.rb', line 34 def fourth self[3] end |
#ninth ⇒ Object
54 55 56 |
# File 'lib/vv/array_methods.rb', line 54 def ninth self[8] end |
#second ⇒ Object
26 27 28 |
# File 'lib/vv/array_methods.rb', line 26 def second self[1] end |
#seventh ⇒ Object
46 47 48 |
# File 'lib/vv/array_methods.rb', line 46 def seventh self[6] end |
#sixth ⇒ Object
42 43 44 |
# File 'lib/vv/array_methods.rb', line 42 def sixth self[5] end |
#spaced ⇒ Object
18 19 20 |
# File 'lib/vv/array_methods.rb', line 18 def spaced self.join(" ") end |
#tenth ⇒ Object
58 59 60 |
# File 'lib/vv/array_methods.rb', line 58 def tenth self[9] end |
#third ⇒ Object
30 31 32 |
# File 'lib/vv/array_methods.rb', line 30 def third self[2] end |