Class: Yoda::Parsing::NodeObjects::ConstNode
- Inherits:
-
Object
- Object
- Yoda::Parsing::NodeObjects::ConstNode
- Defined in:
- lib/yoda/parsing/node_objects/const_node.rb
Instance Attribute Summary collapse
- #node ⇒ Object readonly
Instance Method Summary collapse
- #absolute? ⇒ true, false
-
#initialize(node) ⇒ ConstNode
constructor
A new instance of ConstNode.
- #just_after_separator?(location) ⇒ true, false
- #parent_const ⇒ ConstNode?
- #to_path ⇒ Model::Path
- #to_s(base = nil) ⇒ String
Constructor Details
Instance Attribute Details
#node ⇒ Object (readonly)
6 7 8 |
# File 'lib/yoda/parsing/node_objects/const_node.rb', line 6 def node @node end |
Instance Method Details
#absolute? ⇒ true, false
20 21 22 |
# File 'lib/yoda/parsing/node_objects/const_node.rb', line 20 def absolute? node.children.first == :cbase end |
#just_after_separator?(location) ⇒ true, false
26 27 28 29 |
# File 'lib/yoda/parsing/node_objects/const_node.rb', line 26 def just_after_separator?(location) return false unless node.location.double_colon location == Location.of_ast_location(node.location.double_colon.end) end |
#parent_const ⇒ ConstNode?
15 16 17 |
# File 'lib/yoda/parsing/node_objects/const_node.rb', line 15 def parent_const node.children.first && node.children.first.type == :const ? ConstNode.new(node.children.first) : nil end |
#to_path ⇒ Model::Path
32 33 34 |
# File 'lib/yoda/parsing/node_objects/const_node.rb', line 32 def to_path Model::Path.new(to_s) end |
#to_s(base = nil) ⇒ String
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/yoda/parsing/node_objects/const_node.rb', line 38 def to_s(base = nil) fail ArgumentError, base unless !base || base.is_a?(String) || base.is_a?(Symbol) paths = [] looking_node = node while true return (base ? base.to_s + '::' : '') + paths.join('::') unless looking_node return '::' + paths.join('::') if looking_node.type == :cbase paths.unshift(looking_node.children[1]) looking_node = looking_node.children[0] end end |