Module: NormalizedArrayMethods::InstanceMethods

Includes:
ArraySentence
Included in:
NormalizedArray
Defined in:
lib/doodle/normalized_array.rb

Instance Method Summary collapse

Methods included from ArraySentence

#join_with

Instance Method Details

#<<(value) ⇒ Object



73
74
75
# File 'lib/doodle/normalized_array.rb', line 73

def <<(value)
  super(normalize_value(value))
end

#[](index) ⇒ Object

def ==(other)

  super(normalize_values(*other))
end


85
86
87
# File 'lib/doodle/normalized_array.rb', line 85

def [](index)
  super(normalize_index(index))
end

#[]=(index, value) ⇒ Object



89
90
91
# File 'lib/doodle/normalized_array.rb', line 89

def []=(index, value)
  super(normalize_index(index), normalize_value(value))
end

#at(index) ⇒ Object

def assoc(key)

  super
end


97
98
99
# File 'lib/doodle/normalized_array.rb', line 97

def at(index)
  super(normalize_index(index))
end

#collect!(&block) ⇒ Object

def collect(&block)

  #FIXME
end


109
110
111
# File 'lib/doodle/normalized_array.rb', line 109

def collect!(&block)
  super() {|x| normalize_value(block.call(x))}
end

#concat(other) ⇒ Object

def compact!()

  super
end


121
122
123
# File 'lib/doodle/normalized_array.rb', line 121

def concat(other)
  super(normalize_values(*other))
end

#delete(value) ⇒ Object



125
126
127
# File 'lib/doodle/normalized_array.rb', line 125

def delete(value)
  super(normalize_value(value))
end

#delete_at(index) ⇒ Object



129
130
131
# File 'lib/doodle/normalized_array.rb', line 129

def delete_at(index)
  super(normalize_index(index))
end

#fetch(index) ⇒ Object

def eql?(other)

  super(normalize_values(*other))
end


153
154
155
# File 'lib/doodle/normalized_array.rb', line 153

def fetch(index)
  super(normalize_index(index))
end

#fill(*args, &block) ⇒ Object

array.fill(obj) -> array array.fill(obj, start [, length]) -> array array.fill(obj, range ) -> array array.fill {|index| block } -> array array.fill(start [, length] ) {|index| block } -> array array.fill(range) {|index| block } -> array



163
164
165
166
167
# File 'lib/doodle/normalized_array.rb', line 163

def fill(*args, &block)
  # TODO: check value
  # check start, length
  replace(super)
end

#first(count = 1) ⇒ Object



169
170
171
172
# File 'lib/doodle/normalized_array.rb', line 169

def first(count = 1)
  # TODO: check count
  super
end

#include?(value) ⇒ Boolean

def hash()

  super
end

Returns:

  • (Boolean)


190
191
192
# File 'lib/doodle/normalized_array.rb', line 190

def include?(value)
  super(normalize_value(value))
end

#index(value) ⇒ Object



194
195
196
# File 'lib/doodle/normalized_array.rb', line 194

def index(value)
  super(normalize_value(value))
end

#initialize(*args, &block) ⇒ Object

def -(other)

  super
end


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/doodle/normalized_array.rb', line 33

def initialize(*args, &block)
  #p [:init, 1, args, block]
  if block_given?
    #p [:init, 2]
    original_block = block
    block = proc { |index|
      #p [:init, 3, index]
      normalize_value(original_block[normalize_index(index)])
    }
    #p [:init, 4, block]
  end
  replace(super(*args, &block))
end

#insert(index, *values) ⇒ Object



198
199
200
# File 'lib/doodle/normalized_array.rb', line 198

def insert(index, *values)
  super(normalize_index(index), normalize_values(*values))
end

#last(count = 1) ⇒ Object

def join(sep = $,)

  super
end


210
211
212
213
# File 'lib/doodle/normalized_array.rb', line 210

def last(count = 1)
  # TODO: check count
  super
end

#map!(&block) ⇒ Object

def map(&block)

  super
end


223
224
225
# File 'lib/doodle/normalized_array.rb', line 223

def map!(&block)
  collect!(&block)
end

#normalize_index(index) ⇒ Object

def initialize(*args, &block)

  replace(super)
end


51
52
53
# File 'lib/doodle/normalized_array.rb', line 51

def normalize_index(index)
  index
end

#normalize_indices(*indices) ⇒ Object

convenience method to check indices



61
62
63
# File 'lib/doodle/normalized_array.rb', line 61

def normalize_indices(*indices)
  indices.map{ |index| normalize_index(index) }
end

#normalize_value(value) ⇒ Object



55
56
57
58
# File 'lib/doodle/normalized_array.rb', line 55

def normalize_value(value)
  p [self.class, :normalize_value, value]
  value
end

#normalize_values(*values) ⇒ Object

convenience method to check values



66
67
68
69
70
71
# File 'lib/doodle/normalized_array.rb', line 66

def normalize_values(*values)
  if values.empty?
    values = self
  end
  values.map{ |value| normalize_value(value) }
end

#push(*values) ⇒ Object

def pop()

  super
end


239
240
241
# File 'lib/doodle/normalized_array.rb', line 239

def push(*values)
  super(normalize_values(*values))
end

#reject!(&block) ⇒ Object

def reject(&block)

  super
end


251
252
253
# File 'lib/doodle/normalized_array.rb', line 251

def reject!(&block)
  super() {|x| normalize_value(block.call(x))}
end

#replace(other) ⇒ Object



255
256
257
258
259
260
261
262
# File 'lib/doodle/normalized_array.rb', line 255

def replace(other)
  #p [:replace, other]
  super(other.to_enum(:each_with_index).map{ |v, i|
          #p [:replace_norm, i, v]
          normalize_index(i);
          normalize_value(v)
        })
end

#rindex(value) ⇒ Object

def reverse_each(&block)

  super
end


276
277
278
# File 'lib/doodle/normalized_array.rb', line 276

def rindex(value)
  super(normalize_value(value))
end

#slice(*args) ⇒ Object

array -> obj or nil array[start, length] -> an_array or nil array -> an_array or nil array.slice(index) -> obj or nil array.slice(start, length) -> an_array or nil array.slice(range) -> an_array or nil



296
297
298
299
# File 'lib/doodle/normalized_array.rb', line 296

def slice(*args)
  # TODO: check indices
  super
end

#slice!(*args) ⇒ Object



301
302
303
304
# File 'lib/doodle/normalized_array.rb', line 301

def slice!(*args)
  # TODO: check indices
  super
end

#unshift(*values) ⇒ Object

def uniq!()

  super
end


338
339
340
# File 'lib/doodle/normalized_array.rb', line 338

def unshift(*values)
  super(normalize_values(*values))
end

#values_at(*indices) ⇒ Object Also known as: indexes, indices



342
343
344
# File 'lib/doodle/normalized_array.rb', line 342

def values_at(*indices)
  super(normalize_indices(*indices))
end

#zip(other) ⇒ Object

should this be normalized?



350
351
352
# File 'lib/doodle/normalized_array.rb', line 350

def zip(other)
  super(normalize_values(*other))
end