Class: C::NodeList
- Inherits:
-
Node
show all
- Includes:
- Enumerable
- Defined in:
- lib/cast/node_list.rb,
lib/cast/parse.rb,
lib/cast/node_list.rb
Overview
Abstract base class of the Node list classes.
Constant Summary
Constants inherited
from Node
C::Node::INSPECT_TAB
Instance Attribute Summary
Attributes inherited from Node
#parent, #pos, #subclasses
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Node
#=~, abstract, add_field, #assert_invariants, #attached?, child, #clone, #depth_first, #detach, #detached?, #dup, #each, #eql?, field, fields, #fields, inherited, initializer, #insert_next, #insert_prev, inspect1, #list_next, #list_prev, #method_missing, new_at, #next, #node_after, #node_before, #postorder, #preorder, #prev, #remove_node, #replace_node, #replace_with, #reverse_depth_first, #reverse_each, #reverse_postorder, #reverse_preorder, subclasses_recursive, #swap_with
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class C::Node
Class Method Details
.[](*args) ⇒ Object
18
19
20
|
# File 'lib/cast/node_list.rb', line 18
def self.[](*args)
new.concat(args)
end
|
Instance Method Details
#==(other) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/cast/node_list.rb', line 27
def ==(other)
return false if !other.is_a? C::NodeList
fields.each do |field|
mine = self .send(field.reader)
yours = other.send(field.reader)
mine == yours or return false
end
other = other.to_a
return false if other.length != self.length
each_with_index do |node, i|
return false if node != other[i]
end
return true
end
|
#hash ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/cast/node_list.rb', line 46
def hash
hash = 0
each do |node|
hash ^= node.hash
end
return hash
end
|
#inspect ⇒ Object
58
59
60
|
# File 'lib/cast/node_list.rb', line 58
def inspect
"#{self.class}[#{self.map(&:inspect).join(', ')}]"
end
|
#match?(arr, parser = nil) ⇒ Boolean
40
41
42
43
44
45
46
47
|
# File 'lib/cast/parse.rb', line 40
def match?(arr, parser=nil)
arr = arr.to_a
return false if arr.length != self.length
each_with_index do |node, i|
node.match?(arr[i], parser) or return false
end
return true
end
|
#size ⇒ Object
23
24
25
|
# File 'lib/cast/node_list.rb', line 23
def size
length
end
|
#to_s ⇒ Object
54
55
56
|
# File 'lib/cast/node_list.rb', line 54
def to_s
self.join ', '
end
|