Get substring after the first = symbol in Ruby

后端 未结 5 1686
盖世英雄少女心
盖世英雄少女心 2021-02-02 05:48

Purely out of curiosity, is there a more elegant way to simply get the substring after the first = symbol in a string? The following works to give back name=b

5条回答
  •  不知归路
    2021-02-02 06:38

    Not exactly .after, but quite close to:

    string.partition('=').last
    

    http://www.ruby-doc.org/core-1.9.3/String.html#method-i-partition

提交回复
热议问题