Class: Arrow::Array

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/arrow/array.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/arrow/array.rb', line 23

def new(*args)
  builder_class_name = "#{name}Builder"
  if const_defined?(builder_class_name)
    builder_class = const_get(builder_class_name)
    if builder_class.buildable?(args)
      builder_class.build(*args)
    else
      super
    end
  else
    super
  end
end

Instance Method Details

#[](i) ⇒ Object?

Returns The ‘i`-th value.

‘nil` for NULL value or out of range `i`.

Parameters:

  • i (Integer)

    The index of the value to be gotten.

    You can specify negative index like for ‘::Array#[]`.

Returns:

  • (Object, nil)

    The ‘i`-th value.

    ‘nil` for NULL value or out of range `i`.



47
48
49
50
51
52
53
54
55
# File 'lib/arrow/array.rb', line 47

def [](i)
  i += length if i < 0
  return nil if i < 0 or i >= length
  if null?(i)
    nil
  else
    get_value(i)
  end
end

#eachObject



57
58
59
60
61
62
63
# File 'lib/arrow/array.rb', line 57

def each
  return to_enum(__method__) unless block_given?

  length.times do |i|
    yield(self[i])
  end
end

#reverse_eachObject



65
66
67
68
69
70
71
# File 'lib/arrow/array.rb', line 65

def reverse_each
  return to_enum(__method__) unless block_given?

  (length - 1).downto(0) do |i|
    yield(self[i])
  end
end

#to_arrowObject



73
74
75
# File 'lib/arrow/array.rb', line 73

def to_arrow
  self
end