Write down the methods that you find useful.
str = "aaabbbcccabc" str.count("a") => 4
str = "aaabbbcccabc" str.scan("ab") => [ab, ab] str.scan("ab").length => 2
num = 5 num.abs => 5
num = (-5) num.abs => 5
str = "aabbcc" str.gsub("aa", "") => str = bbcc
Replace aa with an empty string
str = "aabbcc" str.chomp("cc") => aabb
str = "aabbcc" str.delete("bb") => aacc
str = "abc" str.upcase => ABC str.downcase => abc
(1..5).to_a => [1, 2, 3, 4, 5]
array = ["a", "b", "c"] array.push("e"); array = ["a", "b", "c", "e"]
array = ["a", "b", "c"] array.unshif("e"); array = ["e", "a", "b", "c"]
array = ["a", "b", "c", "e"] array.delete("e") array = ["a", "b", "c"] array[0,2] = [] array = ["c"]
Remove two from 0 subscript
array = ["a", "b", "c"] array.map!{|x| x=="a" ? "z" : x} => ["z", "b", "c"]
arrayX = [1, 2, 3] arrayY = ["a", "b", "c"] arrayX.concat(arrayY) arrayX = [1, 2, 3, "a", "b", "c"]
array = [1, 1, 2, 2, 3, 3] array.uniq => [1, 2, 3]
array = ["a", "b", "c"] array.reverse! => ["c", "b", "a"]
str = "abc" str.chars => ["a", "b", "c"]
num = 12345 num.chars => [1, 2, 3, 4, 5]
array = ["a", "b", "c"] array.join => "abc"
Recommended Posts