Class: SyntaxTree::RAssign
Overview
RAssign represents a single-line pattern match.
value in pattern
value => pattern
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.
-
#operator ⇒ Object
readonly
- Kw | Op
-
the operator being used to match against the pattern, which is either => or in.
-
#pattern ⇒ Object
readonly
- untyped
-
the pattern on the right-hand side of the expression.
-
#value ⇒ Object
readonly
- untyped
-
the left-hand expression.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, operator:, pattern:, location:, comments: []) ⇒ RAssign
constructor
A new instance of RAssign.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, operator:, pattern:, location:, comments: []) ⇒ RAssign
Returns a new instance of RAssign.
2950 2951 2952 2953 2954 2955 2956 |
# File 'lib/syntax_tree/node.rb', line 2950 def initialize(value:, operator:, pattern:, location:, comments: []) @value = value @operator = operator @pattern = pattern @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2948 2949 2950 |
# File 'lib/syntax_tree/node.rb', line 2948 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2945 2946 2947 |
# File 'lib/syntax_tree/node.rb', line 2945 def location @location end |
#operator ⇒ Object (readonly)
- Kw | Op
-
the operator being used to match against the pattern, which is
either => or in
2939 2940 2941 |
# File 'lib/syntax_tree/node.rb', line 2939 def operator @operator end |
#pattern ⇒ Object (readonly)
- untyped
-
the pattern on the right-hand side of the expression
2942 2943 2944 |
# File 'lib/syntax_tree/node.rb', line 2942 def pattern @pattern end |
#value ⇒ Object (readonly)
- untyped
-
the left-hand expression
2935 2936 2937 |
# File 'lib/syntax_tree/node.rb', line 2935 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
2958 2959 2960 |
# File 'lib/syntax_tree/node.rb', line 2958 def child_nodes [value, operator, pattern] end |
#deconstruct_keys(keys) ⇒ Object
2964 2965 2966 2967 2968 2969 2970 2971 2972 |
# File 'lib/syntax_tree/node.rb', line 2964 def deconstruct_keys(keys) { value: value, operator: operator, pattern: pattern, location: location, comments: comments } end |
#format(q) ⇒ Object
2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 |
# File 'lib/syntax_tree/node.rb', line 2974 def format(q) q.group do q.format(value) q.text(" ") q.format(operator) q.group do q.indent do q.breakable q.format(pattern) end end end end |
#pretty_print(q) ⇒ Object
2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 |
# File 'lib/syntax_tree/node.rb', line 2988 def pretty_print(q) q.group(2, "(", ")") do q.text("rassign") q.breakable q.pp(value) q.breakable q.pp(operator) q.breakable q.pp(pattern) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 |
# File 'lib/syntax_tree/node.rb', line 3005 def to_json(*opts) { type: :rassign, value: value, op: operator, pattern: pattern, loc: location, cmts: comments }.to_json(*opts) end |