[#79440] [Ruby trunk Bug#13188] Reinitialize Ruby VM. — shyouhei@...
Issue #13188 has been updated by Shyouhei Urabe.
6 messages
2017/02/06
[#79441] Re: [Ruby trunk Bug#13188] Reinitialize Ruby VM.
— SASADA Koichi <ko1@...>
2017/02/06
On 2017/02/06 10:10, shyouhei@ruby-lang.org wrote:
[#79532] Immutable Strings vs Symbols — Daniel Ferreira <subtileos@...>
Hi,
15 messages
2017/02/15
[#79541] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/15
Em 15-02-2017 05:05, Daniel Ferreira escreveu:
[#79543] Re: Immutable Strings vs Symbols
— Daniel Ferreira <subtileos@...>
2017/02/16
Hi Rodrigo,
[#79560] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/16
Em 15-02-2017 22:39, Daniel Ferreira escreveu:
[ruby-core:79502] [Ruby trunk Feature#13207] Allow keyword local variable names like `class` or `for`
From:
kaspth@...
Date:
2017-02-11 15:47:09 UTC
List:
ruby-core #79502
Issue #13207 has been reported by Kasper Timm Hansen.
----------------------------------------
Feature #13207: Allow keyword local variable names like `class` or `for`
https://bugs.ruby-lang.org/issues/13207
* Author: Kasper Timm Hansen
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Sometimes when trying to write expressive Ruby you enevitably hit a case
that would sound just right if the variable name matches a Ruby keyword.
E.g. writing a method to output HTML tags:
```ruby
def label_tag(text, class:)
%(<label class=""#{class.camelize}>#{text}</label>")
end
```
Or a method to generate a representation `for` a specific purpose:
```ruby
def to_gid(for:)
for ||= :universal
GlobalID.generate(self.class.name, id, for)
end
```
Currently Ruby's keywords get in the way of the type of code we'd like to write.
Instead we have to use variable names like `klass` or `modjule`:
```ruby
[ A::B, C::D ].each { |klass| puts klass.name }
```
It would make me a happier programmer if I could write more naturally instead of
worrying about keywords clashing with local variable names.
It also stands to me that far more often when there is a potential clash I want
the variable name to win out. It's unlikely I will be defining classes or
modules within a method say. In those rare cases where I do,
we could expose keywords like this: `Keyword.class`, `Keyword.for` etc.
I propose that renaming a keyword is fair game anywhere except the root scope and
that a rename follows local variable scoping.
NOTE: I think this could also remove the `self` currently needing to be
prepended to `self.class`.
I hope this can be yet another case in Ruby's quest to go a bit out of its way
to make programmers lives happier. Thanks!
--
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>