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.
-
#value ⇒ Object
readonly
- untyped
-
the value being sent to the keyword.
Attributes inherited from Node
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.
3918 3919 3920 3921 3922 |
# File 'lib/syntax_tree/node.rb', line 3918 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
3916 3917 3918 |
# File 'lib/syntax_tree/node.rb', line 3916 def comments @comments end |
#value ⇒ Object (readonly)
- untyped
-
the value being sent to the keyword
3913 3914 3915 |
# File 'lib/syntax_tree/node.rb', line 3913 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3924 3925 3926 |
# File 'lib/syntax_tree/node.rb', line 3924 def child_nodes [value] end |
#deconstruct_keys(keys) ⇒ Object
3930 3931 3932 |
# File 'lib/syntax_tree/node.rb', line 3930 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
3934 3935 3936 3937 3938 3939 3940 3941 3942 |
# File 'lib/syntax_tree/node.rb', line 3934 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
3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 |
# File 'lib/syntax_tree/node.rb', line 3944 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
3955 3956 3957 3958 3959 |
# File 'lib/syntax_tree/node.rb', line 3955 def to_json(*opts) { type: :defined, value: value, loc: location, cmts: comments }.to_json( *opts ) end |