Class: SyntaxTree::Defined
Overview
Defined represents the use of the defined? operator. It can be used with and without parentheses.
defined?(variable)
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- untyped
-
the value being sent to the keyword.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Defined
constructor
A new instance of Defined.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Defined
Returns a new instance of Defined.
4047 4048 4049 4050 4051 |
# File 'lib/syntax_tree/node.rb', line 4047 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4045 4046 4047 |
# File 'lib/syntax_tree/node.rb', line 4045 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4042 4043 4044 |
# File 'lib/syntax_tree/node.rb', line 4042 def location @location end |
#value ⇒ Object (readonly)
- untyped
-
the value being sent to the keyword
4039 4040 4041 |
# File 'lib/syntax_tree/node.rb', line 4039 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
4053 4054 4055 |
# File 'lib/syntax_tree/node.rb', line 4053 def child_nodes [value] end |
#deconstruct_keys(keys) ⇒ Object
4059 4060 4061 |
# File 'lib/syntax_tree/node.rb', line 4059 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
4063 4064 4065 4066 4067 4068 4069 4070 4071 |
# File 'lib/syntax_tree/node.rb', line 4063 def format(q) q.group(0, "defined?(", ")") do q.indent do q.breakable("") q.format(value) end q.breakable("") end end |
#pretty_print(q) ⇒ Object
4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 |
# File 'lib/syntax_tree/node.rb', line 4073 def pretty_print(q) q.group(2, "(", ")") do q.text("defined") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
4084 4085 4086 4087 4088 |
# File 'lib/syntax_tree/node.rb', line 4084 def to_json(*opts) { type: :defined, value: value, loc: location, cmts: comments }.to_json( *opts ) end |