[#66126] Creation/Conversion methods/functions table for Ruby types — SASADA Koichi <ko1@...>
Hi,
5 messages
2014/11/07
[#66289] Re: Creation/Conversion methods/functions table for Ruby types
— Eric Wong <normalperson@...>
2014/11/14
SASADA Koichi <[email protected]> wrote:
[#66293] Re: Creation/Conversion methods/functions table for Ruby types
— SASADA Koichi <ko1@...>
2014/11/14
On 2014/11/15 7:44, Eric Wong wrote:
[#66248] [ruby-trunk - Feature #10423] [PATCH] opt_str_lit*: avoid literal string allocations — normalperson@...
Issue #10423 has been updated by Eric Wong.
3 messages
2014/11/13
[#66595] [ruby-trunk - Bug #10557] [Open] Block not given when the argument is a string — bartosz@...
Issue #10557 has been reported by Bartosz Kopinski.
3 messages
2014/11/30
[ruby-core:66095] [ruby-trunk - Feature #9179] [Assigned] MatchData#values_at should support named capture
From:
naruse@...
Date:
2014-11-05 09:45:05 UTC
List:
ruby-core #66095
Issue #9179 has been updated by Yui NARUSE.
Status changed from Open to Assigned
Assignee set to Yukihiro Matsumoto
I want to write following code, how do you think matz?
```ruby
reg = %r<\A(?<scheme>[A-Za-z][+\-.0-9A-Za-z]*):(?<hier-part>//(?<authority>[^/\\?#]+)(?<path-absolute>/[^?#]*)|[^/?#][^?#]*|)(?:\?(?<query>[^#]*))?(?:#(?<fragment>.*))?\z>
url = "http://example.com/hoge?foo=Bar#frag"
reg =~ url
p $~.values_at(:scheme, :authority, :"path-absolute", :query, :fragment)
```
----------------------------------------
Feature #9179: MatchData#values_at should support named capture
https://bugs.ruby-lang.org/issues/9179#change-49808
* Author: vzvu3k6k _
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: regexp
* Target version:
----------------------------------------
=begin
Using (({MatchData#[]})), we can access a named capture by its name.
/(?<a>...)/.match("foo")[:a] #=> "foo"
/(?<a>...)/.match("foo")["a"] #=> "foo"
But (({MatchData#values_at})) accepts only Integer and refuses Symbol or String.
/(?<a>...)/.match("foo").values_at(:a)
# I expected it returns ["foo"], but...
#=> in `values_at': no implicit conversion of Symbol into Integer (TypeError)
/(?<a>...)/.match("foo").values_at("a")
#=> in `values_at': no implicit conversion of String into Integer (TypeError)
(These are tested in ruby 2.1.0dev (2013-11-28 trunk 43903) [i686-linux].)
I think (({MatchData#values_at})) should work along with (({MathData#[]})) as follows:
/(?<a>...)/.match("foo").values_at(:a) #=> ["foo"]
/(?<a>...)/.match("foo").values_at("a") #=> ["foo"]
In the patch, (({match_entry})) is removed because it is no longer used. Comments and code are based on (({rb_hash_values_at})) in hash.c. It passes (({make test-all})) except (({TestGc#test_gc_reason})), which fails also on the original version.
=end
---Files--------------------------------
matchdata-values_at-named_capture.diff (1.89 KB)
--
https://bugs.ruby-lang.org/