Issue #15991 has been updated by mame (Yusuke Endoh). I couldn't find an existing proposal for a local variable that ends with `?= `. There are many proposals for "attr_reader :foo?" (#5781 #10720 #11167 #= 12046), but all the tickets have been rejected. (#5781 is still open, but = I guess it is just forgotten.) = In #5781, matz is explicitly against an instance variable that ends with `?= `: > I don't want to allow instance variable names ending '?', just because ? = is for predicates, not for variables. So, the point is that we should allow only local variables but not instance= variables. I'm personally a bit negative. ---------------------------------------- Feature #15991: Allow questionmarks in variable names https://bugs.ruby-lang.org/issues/15991#change-79222 * Author: aquaj (J=E9r=E9mie Bonal) * Status: Open * Priority: Normal * Assignee: = * Target version: = ---------------------------------------- Hi, I thought such an issue would've already been discussed but no number of se= arches allowed me to find a similar request. Feel free to close if I missed= a previous refusal. From time to time, especially when trying to clear up complex conditional l= ogic, I find myself wishing I could add `?` to variable names, since I got = used to it while naming methods. For example, currently: ``` if (node? && terminal?) || (halting && (value =3D=3D halting)) # ... end ``` becomes ``` last_node =3D self.node? && self.terminal? halt_on_node =3D halting && (value =3D=3D halting) if last_node || halt_on_node # ... end ``` `halt_on_node` is clear enough, but `last_node` feels like it would contain= a node, instead of expressing its actual purpose ("is the node the last on= e?"). Right now a developer would have two options as I see them: 1 - extract the conditional to a method `def last_node?` which can be a bit= much if it's the only place this code is called. 2 - rename the variable something like `is_last_node`, which feels a bit si= lly since we're in ruby and used to seeing `?`s for predicates. = Trying to assign to a questionmarked variable (`a? =3D true`) raises a `Syn= taxError`. IMHO, it would make for more coherent design to allow it, just l= ike we do in method names. I was afraid that `variable?` would be already parsed as beginning a ternar= y expression (`variable?1:3`) but this isn't parsed either, the only thing = it's used for is for method calls (`a?5 <=3D=3D> a?(5)`), so this change wo= uldn't disrupt any current behavior, the expression would just be looked up= like any other call instead of only looking up methods. The only thing I can see with this is that it might raise the issue of allo= wing `!`s in variable names too, which I'm not sure makes a lot of sense (u= nlike `?` which denotes "booleanness", a trait shared by variables and meth= ods alike, I can't see how a variable would be "dangerous"). -- = https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>