Class: RSpec::Support::Source::Node
- Includes:
- Enumerable
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb
Overview
A wrapper for Ripper AST node which is generated with ‘Ripper.sexp`.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#sexp ⇒ Object
readonly
Returns the value of attribute sexp.
Class Method Summary collapse
Instance Method Summary collapse
- #args ⇒ Object
- #children ⇒ Object
-
#each ⇒ Object
We use a loop here (instead of recursion) to prevent SystemStackError.
- #each_ancestor ⇒ Object
-
#initialize(ripper_sexp, parent = nil) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #location ⇒ Object
- #type ⇒ Object
Methods included from Enumerable
#as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole, #sum
Constructor Details
#initialize(ripper_sexp, parent = nil) ⇒ Node
Returns a new instance of Node.
17 18 19 20 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 17 def initialize(ripper_sexp, parent=nil) @sexp = ripper_sexp.freeze @parent = parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
11 12 13 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 11 def parent @parent end |
#sexp ⇒ Object (readonly)
Returns the value of attribute sexp.
11 12 13 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 11 def sexp @sexp end |
Class Method Details
Instance Method Details
#args ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 26 def args @args ||= raw_args.map do |raw_arg| if Node.sexp?(raw_arg) Node.new(raw_arg, self) elsif Location.location?(raw_arg) Location.new(*raw_arg) elsif raw_arg.is_a?(Array) ExpressionSequenceNode.new(raw_arg, self) else raw_arg end end.freeze end |
#children ⇒ Object
40 41 42 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 40 def children @children ||= args.select { |arg| arg.is_a?(Node) }.freeze end |
#each ⇒ Object
We use a loop here (instead of recursion) to prevent SystemStackError
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 49 def each return to_enum(__method__) unless block_given? node_queue = [] node_queue << self while (current_node = node_queue.shift) yield current_node node_queue.concat(current_node.children) end end |
#each_ancestor ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 61 def each_ancestor return to_enum(__method__) unless block_given? current_node = self while (current_node = current_node.parent) yield current_node end end |
#inspect ⇒ Object
71 72 73 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 71 def inspect "#<#{self.class} #{type}>" end |
#location ⇒ Object
44 45 46 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 44 def location @location ||= args.find { |arg| arg.is_a?(Location) } end |
#type ⇒ Object
22 23 24 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/node.rb', line 22 def type sexp[0] end |