Class: SyntaxTree::ARefField
- Inherits:
-
Object
- Object
- SyntaxTree::ARefField
- Defined in:
- lib/syntax_tree.rb
Overview
ARefField represents assigning values into collections at specific indices. Put another way, it’s any time you’re calling the method #[]=. The ARefField node itself is just the left side of the assignment, and they’re always wrapped in assign nodes.
collection[index] = value
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
- untyped
-
the value being indexed.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#index ⇒ Object
readonly
- nil | Args
-
the value being passed within the brackets.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(collection:, index:, location:, comments: []) ⇒ ARefField
constructor
A new instance of ARefField.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(collection:, index:, location:, comments: []) ⇒ ARefField
Returns a new instance of ARefField.
941 942 943 944 945 946 |
# File 'lib/syntax_tree.rb', line 941 def initialize(collection:, index:, location:, comments: []) @collection = collection @index = index @location = location @comments = comments end |
Instance Attribute Details
#collection ⇒ Object (readonly)
- untyped
-
the value being indexed
930 931 932 |
# File 'lib/syntax_tree.rb', line 930 def collection @collection end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
939 940 941 |
# File 'lib/syntax_tree.rb', line 939 def comments @comments end |
#index ⇒ Object (readonly)
- nil | Args
-
the value being passed within the brackets
933 934 935 |
# File 'lib/syntax_tree.rb', line 933 def index @index end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
936 937 938 |
# File 'lib/syntax_tree.rb', line 936 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
948 949 950 |
# File 'lib/syntax_tree.rb', line 948 def child_nodes [collection, index] end |
#format(q) ⇒ Object
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 |
# File 'lib/syntax_tree.rb', line 952 def format(q) q.group do q.format(collection) q.text("[") if index q.indent do q.breakable("") q.format(index) end q.breakable("") end q.text("]") end end |
#pretty_print(q) ⇒ Object
969 970 971 972 973 974 975 976 977 978 979 980 981 |
# File 'lib/syntax_tree.rb', line 969 def pretty_print(q) q.group(2, "(", ")") do q.text("aref_field") q.breakable q.pp(collection) q.breakable q.pp(index) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
983 984 985 986 987 988 989 990 991 |
# File 'lib/syntax_tree.rb', line 983 def to_json(*opts) { type: :aref_field, collection: collection, index: index, loc: location, cmts: comments }.to_json(*opts) end |