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

Class Method Details

.included(base) ⇒ Object



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

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

Instance Method Details

#eighthObject



84
85
86
# File 'lib/vv/array_methods.rb', line 84

def eighth
  self[7]
end

#fifthObject



72
73
74
# File 'lib/vv/array_methods.rb', line 72

def fifth
  self[4]
end

#format!(other) ⇒ Object



56
57
58
# File 'lib/vv/array_methods.rb', line 56

def format!(other)
  self.spaced.format! other
end

#fourthObject



68
69
70
# File 'lib/vv/array_methods.rb', line 68

def fourth
  self[3]
end

#gravifyObject



16
17
18
19
20
# File 'lib/vv/array_methods.rb', line 16

def gravify
  self.collect do |elem|
    "`#{elem}`"
  end
end

#gravify!Object



22
23
24
25
26
# File 'lib/vv/array_methods.rb', line 22

def gravify!
  self.collect! do |elem|
    "`#{elem}`"
  end
end

#include_any?(other) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/vv/array_methods.rb', line 35

def include_any?(other)
  self.includes_any?(other)
end

#includes_any?(other) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (TypeError)


28
29
30
31
32
33
# File 'lib/vv/array_methods.rb', line 28

def includes_any?(other)
  raise TypeError, "Expecting array" unless other.is_a? Array
  uother = other.uniq
  uself  = self.uniq
  (uself + uother).uniq.size < (uself.size + uother.size)
end

#ninthObject



88
89
90
# File 'lib/vv/array_methods.rb', line 88

def ninth
  self[8]
end

#secondObject



60
61
62
# File 'lib/vv/array_methods.rb', line 60

def second
  self[1]
end

#seventhObject



80
81
82
# File 'lib/vv/array_methods.rb', line 80

def seventh
  self[6]
end

#sixthObject



76
77
78
# File 'lib/vv/array_methods.rb', line 76

def sixth
  self[5]
end

#spacedObject



52
53
54
# File 'lib/vv/array_methods.rb', line 52

def spaced
  self.join(" ")
end

#stringify_collection(grave: false) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vv/array_methods.rb', line 39

def stringify_collection grave: false
  return self.gravify.stringify_collection if grave

  return String.empty_string if self.blank?
  return self.first          if self.size == 1
  return self.join " and "   if self.size == 2

  new_collection = self[0..-3]
  back_fragment  = self[-2..-1].join ", and "
  new_collection << back_fragment
  new_collection.join ", "
end

#tenthObject



92
93
94
# File 'lib/vv/array_methods.rb', line 92

def tenth
  self[9]
end

#thirdObject



64
65
66
# File 'lib/vv/array_methods.rb', line 64

def third
  self[2]
end