[#73707] [Ruby trunk Misc#12004] Code of Conduct — hanmac@...
Issue #12004 has been updated by Hans Mackowiak.
3 messages
2016/02/05
[#73730] [Ruby trunk Feature#12034] RegExp does not respect file encoding directive — nobu@...
Issue #12034 has been updated by Nobuyoshi Nakada.
3 messages
2016/02/07
[#73746] [Ruby trunk Feature#12034] RegExp does not respect file encoding directive — nobu@...
Issue #12034 has been updated by Nobuyoshi Nakada.
3 messages
2016/02/09
[#73919] [Ruby trunk Feature#11262] Make more objects behave like "Functions" — Ruby-Lang@...
Issue #11262 has been updated by J旦rg W Mittag.
3 messages
2016/02/22
[#74019] [Ruby trunk Bug#12103][Rejected] ruby process hangs while executing regular expression. — duerst@...
Issue #12103 has been updated by Martin D端rst.
3 messages
2016/02/27
[ruby-core:73839] [Ruby trunk Feature#11999] MatchData#to_h to get a Hash from named captures
From:
her@...
Date:
2016-02-16 11:25:00 UTC
List:
ruby-core #73839
Issue #11999 has been updated by sorah Shota Fukumori.
Assignee set to sorah Shota Fukumori
Discussed at https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20160216Japan with Matz and several committers:
Log: https://docs.google.com/document/d/1rj7ODOCSfcsQeBd6-p-NiVwqxDUg05G66LwDOkKOGTw/pub
- #to_h is inappropriate name while non-named capture exists:
1. Return Hash with integer keys? ( `{0 => "a", 1 => "b"}` )
- there's no use case for this behavior.
- rejected
2. `#named_captures` (accepted)
- matz said acceptable
- Behavior when there are multiple named captures with same name
- Return last matched value
``` ruby
/(?<a>b)|(?<a>x)/.match("abc").to_h #=> {"a" => "b"}
```
- Behavior when named captures didn’t match anything
- Return nil as value
- Behavior when no named captures
- `#captures` returns `[]` when a regexp has no capture, so `#named_captures` returns `{}` when a regexp has no named capture
----
@matz Could you confirm this ↑ and say accept here please?
----------------------------------------
Feature #11999: MatchData#to_h to get a Hash from named captures
https://bugs.ruby-lang.org/issues/11999#change-57015
* Author: sorah Shota Fukumori
* Status: Open
* Priority: Normal
* Assignee: sorah Shota Fukumori
----------------------------------------
~~~
class MatchData
def to_h
self.names.map { |n| [n, self[n]] }.to_h
end
end
p '12'.match(/(?<a>.)(?<b>.)(?<c>.)?/).to_h #=> {"a"=>"1", "b"=>"2", "c"=>nil}
~~~
Sometimes I want to get a Hash from named capture, but currently I have to use #names + #captures. How about adding MatchData#to_h for convenience way?
---Files--------------------------------
11999.diff (2.77 KB)
--
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>