Ruby/String/delete

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

Get rid of that extra l in alll:

puts "That"s alll folks".delete "l"



negate all or part of an argument with the caret (^), similar to its use in regular expressions

puts "That"s all folks".delete "abcdefghijklmnopqrstuvwxyz", "^ha"



use two ls instead of one for delete method

puts "That"s alll folks".delete "ll"



When there is more than one argument, take the intersection.

# Arguments that begin with ^ are negated.
"hello".count("a-z", "^aeiou")   # => 3: count lowercase consonants
"hello".delete("a-z", "^aeiou")  # => "eo: delete lowercase consonants



With delete or delete!, you can delete characters from a string

puts "That"s call folks!".delete "c"