Class: SyntaxTree::SClass
Overview
SClass represents a block of statements that should be evaluated within the context of the singleton class of an object. It’s frequently used to define singleton methods.
class << self
end
Instance Attribute Summary collapse
-
#bodystmt ⇒ Object
readonly
- BodyStmt
-
the expressions to be executed.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#target ⇒ Object
readonly
- Node
-
the target of the singleton class to enter.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(target: nil, bodystmt: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, bodystmt:, location:) ⇒ SClass
constructor
A new instance of SClass.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(target:, bodystmt:, location:) ⇒ SClass
Returns a new instance of SClass.
9818 9819 9820 9821 9822 9823 |
# File 'lib/syntax_tree/node.rb', line 9818 def initialize(target:, bodystmt:, location:) @target = target @bodystmt = bodystmt @location = location @comments = [] end |
Instance Attribute Details
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed
9813 9814 9815 |
# File 'lib/syntax_tree/node.rb', line 9813 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9816 9817 9818 |
# File 'lib/syntax_tree/node.rb', line 9816 def comments @comments end |
#target ⇒ Object (readonly)
- Node
-
the target of the singleton class to enter
9810 9811 9812 |
# File 'lib/syntax_tree/node.rb', line 9810 def target @target end |
Instance Method Details
#===(other) ⇒ Object
9869 9870 9871 9872 |
# File 'lib/syntax_tree/node.rb', line 9869 def ===(other) other.is_a?(SClass) && target === other.target && bodystmt === other.bodystmt end |
#accept(visitor) ⇒ Object
9825 9826 9827 |
# File 'lib/syntax_tree/node.rb', line 9825 def accept(visitor) visitor.visit_sclass(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9829 9830 9831 |
# File 'lib/syntax_tree/node.rb', line 9829 def child_nodes [target, bodystmt] end |
#copy(target: nil, bodystmt: nil, location: nil) ⇒ Object
9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 |
# File 'lib/syntax_tree/node.rb', line 9833 def copy(target: nil, bodystmt: nil, location: nil) node = SClass.new( target: target || self.target, bodystmt: bodystmt || self.bodystmt, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
9847 9848 9849 9850 9851 9852 9853 9854 |
# File 'lib/syntax_tree/node.rb', line 9847 def deconstruct_keys(_keys) { target: target, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 |
# File 'lib/syntax_tree/node.rb', line 9856 def format(q) q.text("class << ") q.group do q.format(target) q.indent do q.breakable_force q.format(bodystmt) end q.breakable_force end q.text("end") end |