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
- untyped
-
the target of the singleton class to enter.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, bodystmt:, location:, comments: []) ⇒ SClass
constructor
A new instance of SClass.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(target:, bodystmt:, location:, comments: []) ⇒ SClass
Returns a new instance of SClass.
7940 7941 7942 7943 7944 7945 |
# File 'lib/syntax_tree/node.rb', line 7940 def initialize(target:, bodystmt:, location:, comments: []) @target = target @bodystmt = bodystmt @location = location @comments = comments end |
Instance Attribute Details
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed
7935 7936 7937 |
# File 'lib/syntax_tree/node.rb', line 7935 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7938 7939 7940 |
# File 'lib/syntax_tree/node.rb', line 7938 def comments @comments end |
#target ⇒ Object (readonly)
- untyped
-
the target of the singleton class to enter
7932 7933 7934 |
# File 'lib/syntax_tree/node.rb', line 7932 def target @target end |
Instance Method Details
#accept(visitor) ⇒ Object
7947 7948 7949 |
# File 'lib/syntax_tree/node.rb', line 7947 def accept(visitor) visitor.visit_sclass(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7951 7952 7953 |
# File 'lib/syntax_tree/node.rb', line 7951 def child_nodes [target, bodystmt] end |
#deconstruct_keys(_keys) ⇒ Object
7957 7958 7959 7960 7961 7962 7963 7964 |
# File 'lib/syntax_tree/node.rb', line 7957 def deconstruct_keys(_keys) { target: target, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 |
# File 'lib/syntax_tree/node.rb', line 7966 def format(q) q.group(0, "class << ", "end") do q.format(target) q.indent do q.breakable(force: true) q.format(bodystmt) end q.breakable(force: true) end end |