Class: RAXB::ElementList
- Inherits:
-
Array
- Object
- Array
- RAXB::ElementList
show all
- Defined in:
- lib/raxb.rb
Instance Method Summary
collapse
Constructor Details
#initialize(parent, name) ⇒ ElementList
Returns a new instance of ElementList.
21
22
23
24
25
|
# File 'lib/raxb.rb', line 21
def initialize(parent, name)
super()
@parent = parent
@name = name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
61
62
63
64
|
# File 'lib/raxb.rb', line 61
def method_missing( name, *args )
name = name.to_s
self[0].send( name, *args )
end
|
Instance Method Details
#<<(element) ⇒ Object
27
28
29
|
# File 'lib/raxb.rb', line 27
def <<(element)
self[0] << element
end
|
#[](i) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/raxb.rb', line 31
def [](i)
if i == size
if i == 1 and !at(0).exists?
raise "Index out of bounds: (#{i}) when size=#{size}"
end
m = Element.new(@name, @parent)
push m
return m
elsif i < size
return at(i)
else
raise "Index out of bounds: (#{i}) when size=#{size}"
end
end
|
#[]=(i, element) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/raxb.rb', line 46
def []=(i,element)
if 0 <= i and i < size
rexml = element.to_rexml.dup
@parent.to_rexml.elements[i+1] = rexml
fill Element.new(rexml, @parent, true), i, 1
else
raise "Index out of bounds: (#{i}) when size=#{size}"
end
end
|