Issue #14443 has been updated by shevegen (Robert A. Heiler).


To quote from the other issue and what shyouhei wrote there:

"While I claimed the use of regular expression is an implementation detail that I don't want to care about, attendees there said it is better to expose compiled structure (be they regexp) for performance. I agree with that, so I give up this propossal."


----------------------------------------
Feature #14443: Omit 'pattern' parameter in '(g)sub(!)' when 'hash' is given
https://bugs.ruby-lang.org/issues/14443#change-70184

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
When `(g)sub(!)` takes a hash as the second argument, in almost all use cases, the first argument expresses the union of keys of the hash. In the following, `/[abc]/` is the union of the keys `"a"`, `"b"`, `"c"`.

```ruby
"blahblah".sub(/[abc]/, {"a" => "A", "b" => "B", "c" => "C"})
```

I feel this redundant and not efficient. Hence I propose to let the current first argument be optional when a hash is given. The following:


```ruby
"blahblah".sub("a" => "A", "b" => "B", "c" => "C")
```

should be equivalent to:


```ruby
"blahblah".sub(pattern, {"a" => "A", "b" => "B", "c" => "C"})
```

where:

```ruby
pattern = Regexp.union(*{"a" => "A", "b" => "B", "c" => "C"}.keys.map{|k| Regexp.escape(k)})
```



-- 
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>