3 ms·
Wait, is :state a keyword or an instance attribute? Using the same syntax for both seems really confusing.
by nerdponx 3y ago
Wait, is :state a keyword or an instance attribute? Using the same syntax for both seems really confusing.
- deschutes 3y agoIt's a symbol. Basically a glorified string literal.
- lloeki 3y agoIt's more like an integer with a textual name.
- vidarh 3y agoRuby doesn't have "instance attributes". Instance variables are prefixed with "@". Anything prefixed by ":" is a symbol. In some contexts we use symbols to refer to methods by name. Anything you might thing is an "attribute" is likely a method. E.g. on some_object.name, name is always a method. You might be confused because e.g. "attr_reader" takes symbol arguments, because it's just another method. E.g. "attr_reader :foo" defines a method named "foo" to return "@foo". ":foo" there is a Symbol representing the name "foo".
- nerdponx 3y agoSo it's just a symbol, but in this context it will be used to look up the "state" method? Not unlike how symbols are sometimes used as "designators" of various things in Lisp?