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.
890 891 892 893 894 895 |
# File 'lib/syntax_tree.rb', line 890 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
879 880 881 |
# File 'lib/syntax_tree.rb', line 879 def collection @collection end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
888 889 890 |
# File 'lib/syntax_tree.rb', line 888 def comments @comments end |
#index ⇒ Object (readonly)
- nil | Args
-
the value being passed within the brackets
882 883 884 |
# File 'lib/syntax_tree.rb', line 882 def index @index end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
885 886 887 |
# File 'lib/syntax_tree.rb', line 885 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
897 898 899 |
# File 'lib/syntax_tree.rb', line 897 def child_nodes [collection, index] end |
#format(q) ⇒ Object
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 |
# File 'lib/syntax_tree.rb', line 901 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
918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'lib/syntax_tree.rb', line 918 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
932 933 934 935 936 937 938 939 940 |
# File 'lib/syntax_tree.rb', line 932 def to_json(*opts) { type: :aref_field, collection: collection, index: index, loc: location, cmts: comments }.to_json(*opts) end |