Help us understand the problem. What is going on with this article?

RubyのString#deleteの意外な機能

More than 3 years have passed since last update.

Stringクラスのインスタンスメソッド、「delete」
その名の通り、レシーバの文字列から引数の文字列を消すメソッド。

a = '12345'
puts a.delete('3')

# => 1245

単語単位ではなく、文字で消すのが注意すべきところだが、、、

a = '12345'
puts a.delete('35')

# => 124

ここまではまぁ大丈夫。

しかし、こんな引数の書き方が存在する。

a = '12345'
puts a.delete('3-5')

これを実行すると。。。

# => 12

範囲もかけるらしい。。。

いやいや。いらないいらない。笑

20160826更新

こんなのもできた

# 改行して文字列を作ると、strに¥nと空白が入ってしまう
str = "http://hogehoge.com
        /fuga
        /piyo".delete("¥n| ") # or

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした