From: yugui@... Date: 2018-05-13T23:32:58+00:00 Subject: [ruby-core:87011] [Ruby trunk Feature#14249] Remove str[match_str] Issue #14249 has been updated by yugui (Yuki Sonoda). IIUC, Ana is saying that `str[match_str]` does not make sense because it always returns `match_str`. But it does make sense because it returns `nil` if `str` does not contain such a substring. i.e. it is useful to test if the string contains a substring. You would say that `str[regex]` can do the same thing. And theoretically it is true. But it also means you must compile `match_str` into `Regexp` beforehand. So `str[match_str]` is a convenient (and sometimes more efficient) way to test substrings. Then, you might say that `str.contains` can do the same thing. And theoretically it is true. Here `str[match_str]` is necessary to just keep compatibility between `String` and `Regexp`. Since most of all methods in the standard library which expect a pattern of character sequence accepts both of `String` and `Regexp`, it is natural for users to expect that the compatibility is kept in `String#[]` too. ---------------------------------------- Feature #14249: Remove str[match_str] https://bugs.ruby-lang.org/issues/14249#change-71978 * Author: ana06 (Ana Maria Martinez Gomez) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- I wonder if `str[match_str]` makes sense. ``` Ruby "ana"['a'] => "a" ``` I would say this is not expected and it brings problems, for example when accessing nested hashes. For example: ``` Ruby params = { "user" => "Nicolas Cage" } => {"user"=>"Nicolas Cage"} params["user"]["age"] => "age" ``` I think `str[regexp]` is enough and that `str[match_str]` can be removed. -- https://bugs.ruby-lang.org/ Unsubscribe: