[#70257] [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI — ko1@...

Issue #11420 has been reported by Koichi Sasada.

11 messages 2015/08/06

[ruby-core:70321] [Ruby trunk - Feature #11429] Local variable assignment via regex ===

From: nobu@...
Date: 2015-08-10 23:26:11 UTC
List: ruby-core #70321
Issue #11429 has been updated by Nobuyoshi Nakada.

Description updated

They are different stories.

Enabling assignment via `Regexp#===` doesn't mean it via `when`.

----------------------------------------
Feature #11429: Local variable assignment via regex === 
https://bugs.ruby-lang.org/issues/11429#change-53741

* Author: Sean Linsley
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Currently, this assigns the `username` variable:

```ruby
/(?<username>.*)@.*\..*/ =~ "seanlinsley@example.com"
```

But this does not:

```ruby
/(?<username>.*)@.*\..*/ === "seanlinsley@example.com"
```

If it did, it would be possible to set variables during a case statement, which was my original goal:

```ruby
case "seanlinsley@example.com"
when /(?<username>.*)@.*\..*/
  puts "Username is: #{username}"
end
```

I would be happy to implement this, if it's a desired feature.



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

In This Thread

Prev Next