Module: ValidArray::Functions

Defined in:
lib/valid_array/functions.rb

Overview

The functions that get included into ValidArray

Instance Method Summary collapse

Instance Method Details

#&(ary) ⇒ Object

Validates outcome. See Array#&



21
22
23
# File 'lib/valid_array/functions.rb', line 21

def &(ary)
  self.class.new super
end

#*(int) ⇒ Object

Validates outcome. See Array#*



26
27
28
# File 'lib/valid_array/functions.rb', line 26

def *(int)
  self.class.new super
end

#+(ary) ⇒ Object

Validates outcome. See Array#+



31
32
33
# File 'lib/valid_array/functions.rb', line 31

def +(ary)
  self.class.new super
end

#<<(item) ⇒ Object

Validates outcome. See Array#<<



36
37
38
39
40
41
# File 'lib/valid_array/functions.rb', line 36

def <<(item)
  begin
    item = self.class.validate item
    super
  rescue DontInsertException; end
end

#[](idx) ⇒ Object

Validates outcome. See Array#[]



44
45
46
# File 'lib/valid_array/functions.rb', line 44

def [](idx)
  self.class.new super
end

#[]=(idx, item) ⇒ Object

Validates outcome. See Array#[]=



54
55
56
57
58
59
# File 'lib/valid_array/functions.rb', line 54

def []=(idx, item)
  begin
    item = self.class.validate item
    super
  rescue DontInsertException; end
end

#concat(other_ary) ⇒ Object

Validates outcome. See Array#concat



62
63
64
65
# File 'lib/valid_array/functions.rb', line 62

def concat(other_ary)
  other_ary = _ensure_array_is_valid other_ary
  super
end

#fill(*args, &block) ⇒ Object

Validates outcome. See Array#fill



74
75
76
77
78
# File 'lib/valid_array/functions.rb', line 74

def fill(*args, &block)
  ary = self.to_a
  ary.fill *args, &block
  self.replace ary
end

#initialize(*args, &block) ⇒ Object

Validates outcome. See Array#initialize



9
10
11
12
# File 'lib/valid_array/functions.rb', line 9

def initialize(*args, &block)
  ary = Array.new *args, &block
  self.replace ary
end

#map!(&block) ⇒ Object

Validates outcome. See Array#map!



93
94
95
# File 'lib/valid_array/functions.rb', line 93

def map!(&block)
  self.replace(self.map &block)
end

#push(*items) ⇒ Object

Validates outcome. See Array#push



81
82
83
84
# File 'lib/valid_array/functions.rb', line 81

def push(*items)
  items = _ensure_array_is_valid items
  super
end

#replace(other_ary) ⇒ Object

Validates outcome. See Array#replace



15
16
17
18
# File 'lib/valid_array/functions.rb', line 15

def replace(other_ary)
  other_ary = _ensure_array_is_valid other_ary
  super
end

#slice(*args) ⇒ Object

Validates outcome. See Array#slice



49
50
51
# File 'lib/valid_array/functions.rb', line 49

def slice(*args)
  self.class.new super
end

#unshift(*items) ⇒ Object

Validates outcome. See Array#unshift



87
88
89
90
# File 'lib/valid_array/functions.rb', line 87

def unshift(*items)
  items = _ensure_array_is_valid items
  super
end