Class: TurboTest::StaticAnalysis::Constants::Node
- Inherits:
-
Object
- Object
- TurboTest::StaticAnalysis::Constants::Node
- Defined in:
- lib/turbo_test_static_analysis/constants/node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#end_pos ⇒ Object
Returns the value of attribute end_pos.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#singleton ⇒ Object
readonly
Returns the value of attribute singleton.
-
#start_pos ⇒ Object
readonly
Returns the value of attribute start_pos.
-
#top_level ⇒ Object
Returns the value of attribute top_level.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #contains?(node) ⇒ Boolean
- #full_name ⇒ Object
-
#initialize(name:, start_pos:, end_pos:, singleton: false, definition: false) ⇒ Node
constructor
A new instance of Node.
- #named_singleton_with_parent? ⇒ Boolean
- #parent_is_named_singleton? ⇒ Boolean
- #root ⇒ Object
Constructor Details
#initialize(name:, start_pos:, end_pos:, singleton: false, definition: false) ⇒ Node
Returns a new instance of Node.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 10 def initialize(name:, start_pos:, end_pos:, singleton: false, definition: false) @name = name @children = [] @start_pos = start_pos @end_pos = end_pos @parent = nil @singleton = singleton @definition = definition @top_level = false end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
7 8 9 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 7 def children @children end |
#definition ⇒ Object
Returns the value of attribute definition.
8 9 10 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 8 def definition @definition end |
#end_pos ⇒ Object
Returns the value of attribute end_pos.
8 9 10 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 8 def end_pos @end_pos end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 7 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 7 def parent @parent end |
#singleton ⇒ Object (readonly)
Returns the value of attribute singleton.
7 8 9 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 7 def singleton @singleton end |
#start_pos ⇒ Object (readonly)
Returns the value of attribute start_pos.
7 8 9 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 7 def start_pos @start_pos end |
#top_level ⇒ Object
Returns the value of attribute top_level.
8 9 10 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 8 def top_level @top_level end |
Instance Method Details
#add_child(child) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 21 def add_child(child) return if child.start_pos == start_pos && child.name == name return unless contains?(child) @children << child child.instance_variable_set(:@parent, self) child.instance_variable_set(:@definition, definition) child end |
#contains?(node) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 31 def contains?(node) ((@start_pos <=> node.start_pos) == -1 && (@end_pos <=> node.end_pos) == 1) || ((@start_pos <=> node.start_pos).zero? && ((@end_pos <=> node.end_pos).zero? || (@end_pos <=> node.end_pos) == 1)) end |
#full_name ⇒ Object
37 38 39 40 41 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 37 def full_name return @name unless @parent [@parent.full_name, @name].compact.join("::") end |
#named_singleton_with_parent? ⇒ Boolean
55 56 57 58 59 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 55 def named_singleton_with_parent? return false unless parent singleton && name != "singleton_class" end |
#parent_is_named_singleton? ⇒ Boolean
49 50 51 52 53 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 49 def parent_is_named_singleton? return false unless parent parent.singleton && parent.name != "singleton_class" end |
#root ⇒ Object
43 44 45 46 47 |
# File 'lib/turbo_test_static_analysis/constants/node.rb', line 43 def root return self if parent.nil? parent.root end |