Issue #12096 has been updated by Shyouhei Urabe.


At the developer's meeting yesterday we looked at this issue.  As OP refers to instance_variable_set, this is a metaprogramming syntax by nature.  And it seems there are no other _syntax_ that does metaprogramming like this.  Meeting attendees argued this point.

----------------------------------------
Feature #12096: New notation for instance variables and class variables
https://bugs.ruby-lang.org/issues/12096#change-57529

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In order to create symbols that include non-word characters, we have the `:'...'` notation:

~~~RUBY
:'foo-bar'
:"foo-bar"
~~~

What about extending this notation to instance variables and class variables? The use case is to solve the problems raised in #12046, #11167, #10720. There, the problem was that, even though we can have methods like `foo?` or symbols like `:foo?`, we cannot have corresponding instance variables. My proposal is to introduce a similar notation for instance variables:

~~~RUBY
@'foo?'
@"foo?"
~~~

I can't think of a similar use case for class variables, but there is no reason to make class variables to behave different from instance variables more than necessary, so there can also be the corresponding notation for class variables:

~~~RUBY
@@'foo?'
@@"foo?"
~~~

Right now, these notations raise syntax errors, so I don't think it conflicts (raises ambiguity) with the existing syntax.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>