Class: Prune::PObjects::PArray
- Inherits:
-
Base
- Object
- Base
- Prune::PObjects::PArray
show all
- Defined in:
- lib/prune/p_objects/p_array.rb
Constant Summary
collapse
- LF_SIZE =
Size to line feed when converted to String.
10
Instance Method Summary
collapse
Methods inherited from Base
#indent!, #outdent!, #space, #value_to_s
Constructor Details
#initialize(*args) ⇒ PArray
10
11
12
|
# File 'lib/prune/p_objects/p_array.rb', line 10
def initialize(*args)
@array = args
end
|
Instance Method Details
#<<(value) ⇒ Object
18
19
20
|
# File 'lib/prune/p_objects/p_array.rb', line 18
def <<(value)
@array << value
end
|
#[](key) ⇒ Object
22
23
24
|
# File 'lib/prune/p_objects/p_array.rb', line 22
def [](key)
@array[key]
end
|
#[]=(key, value) ⇒ Object
26
27
28
|
# File 'lib/prune/p_objects/p_array.rb', line 26
def []=(key, value)
@array[key] = value
end
|
#empty? ⇒ Boolean
14
15
16
|
# File 'lib/prune/p_objects/p_array.rb', line 14
def empty?
@array.empty?
end
|
#size ⇒ Object
30
31
32
|
# File 'lib/prune/p_objects/p_array.rb', line 30
def size
@array.size
end
|
#to_s ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/prune/p_objects/p_array.rb', line 34
def to_s
unless self.empty?
if @array.size > LF_SIZE
head = @array[0, LF_SIZE]
tail = @array[LF_SIZE, @array.size]
out = []
out << "[ %s" % head.collect{|item| value_to_s(item)}.join(" ")
indent!
tail.each_slice(LF_SIZE){|slice|
out << space + slice.collect{|item| value_to_s(item)}.join(" ")
}
outdent!
out[out.size - 1] += " ]"
out.join(LF)
else
"[ %s ]" % @array.collect{|item| value_to_s(item)}.join(" ")
end
else
"[ ]"
end
end
|