キーワード
- % (12)
- * (12)
- + (12)
- +@ (10)
- -@ (10)
- << (12)
- <=> (12)
- == (12)
- === (12)
- =~ (12)
- [] (72)
- []= (84)
- byteindex (3)
- byterindex (3)
- bytes (24)
- bytesize (12)
- byteslice (36)
- capitalize (12)
- capitalize! (12)
- casecmp (12)
- casecmp? (9)
- center (12)
- chars (24)
- chomp (12)
- chomp! (12)
- chop (12)
- chop! (12)
- chr (12)
- codepoints (24)
- concat (21)
- count (12)
- crypt (12)
- dedup (3)
- delete (12)
- delete! (12)
-
delete
_ prefix (8) -
delete
_ prefix! (8) -
delete
_ suffix (8) -
delete
_ suffix! (8) - downcase (12)
- downcase! (12)
- dump (8)
-
each
_ byte (24) -
each
_ char (24) -
each
_ codepoint (24) -
each
_ grapheme _ cluster (16) -
each
_ line (24) - encode (36)
- encode! (24)
- encoding (12)
-
end
_ with? (12) - eql? (12)
-
force
_ encoding (12) - getbyte (12)
-
grapheme
_ clusters (16) - gsub (48)
- gsub! (48)
- hash (12)
- hex (12)
- include? (12)
- index (12)
- insert (12)
- inspect (12)
- length (12)
- lines (24)
- ljust (12)
- lstrip (12)
- match (24)
- match? (9)
- next! (12)
- oct (12)
- ord (12)
-
parse
_ csv (12) - partition (12)
- prepend (21)
- rindex (12)
- rjust (12)
- rpartition (12)
- rstrip (12)
- rstrip! (12)
- scan (24)
- scrub (36)
- scrub! (36)
- setbyte (12)
- size (12)
- slice (72)
- split (19)
- squeeze (12)
- squeeze! (12)
-
start
_ with? (12) - strip (12)
- strip! (12)
- sub (36)
- sub! (36)
- succ! (12)
- sum (12)
- swapcase (12)
- swapcase! (12)
-
to
_ c (12) -
to
_ f (12) -
to
_ i (12) -
to
_ r (12) - tr (12)
-
tr
_ s (12) -
tr
_ s! (12) - undump (8)
-
unicode
_ normalize (11) -
unicode
_ normalize! (11) -
unicode
_ normalized? (11) - unpack (12)
- unpack1 (9)
- upcase (12)
- upcase! (12)
- upto (12)
検索結果
先頭5件
-
String
# to _ f -> Float (30080.0) -
文字列を 10 進数表現と解釈して、浮動小数点数 Float に変換します。
...象とします。
途中に変換できないような文字列がある場合、それより先の文字列は無視されます。
//emlist[][ruby]{
p "-10".to_f # => -10.0
p "10e2".to_f # => 1000.0
p "1e-2".to_f # => 0.01
p ".1".to_f # => 0.1
p "1_0_0".to_f # => 100.0 # 数値リテラ......数とみなせるものがないため、0.0 を返します。
変換対象が空文字列のケースでも、0.0 を返します。
//emlist[][ruby]{
p "".to_f # => 0.0
p "nan".to_f # => 0.0
p "INF".to_f # => 0.0
p "-Inf".to_f # => 0.0
//}
変換後の Float が有限の値を取れ......[][ruby]{
#!ruby -W2
p ("10" * 1000).to_f # => Infinity
# warning: Float 10101010101010101010... out of range
//}
なお、このメソッドとは逆に、数値を文字列に変換するには
Kernel.#sprintf, String#%, Integer#to_s
を使用します。
@see String#hex, String#oct, String#t... -
String
# []=(nth , val) (30077.0) -
nth 番目の文字を文字列 val で置き換えます。
...nth 番目の文字を文字列 val で置き換えます。
@param nth 置き換えたい文字の位置を指定します。
@param val 置き換える文字列を指定します。
@return val を返します。
//emlist[例][ruby]{
buf = "string"
buf[1] = "!!"
p buf # => "s!!ring"
//}... -
String
# []=(regexp , name , val) (30077.0) -
正規表現 regexp の name で指定した名前付きキャプチャにマッチする最初の 部分文字列を文字列 val で置き換えます。
...ます。
@param regexp 置き換えたい部分文字列のパターンを示す正規表現
@param name 置き換えたい部分文字列のパターンを示す正規表現レジスタを示す名前
@param val 指定範囲の部分文字列と置き換えたい文字列
@return v......al を返します。
@raise IndexError name で指定した名前付きキャプチャが存在しない場合に発
生します。
//emlist[例][ruby]{
s = "FooBar"
s[/(?<foo>[A-Z]..)(?<bar>[A-Z]..)/, "foo"] = "Baz"
p s # => "BazBar"
//}... -
String
# []=(regexp , nth , val) (30077.0) -
正規表現 regexp の nth 番目の括弧にマッチする 最初の部分文字列を文字列 val で置き換えます。
...えます。
@param regexp 置き換えたい部分文字列のパターンを示す正規表現
@param nth 置き換えたい部分文字列のパターンを示す正規表現レジスタの番号
@param val 指定範囲の部分文字列と置き換えたい文字列
@return val......を返します。
@raise IndexError 正規表現がマッチしなかった場合に発生します。
//emlist[例][ruby]{
buf = "def exec(cmd)"
buf[/def\s+(\w+)/, 1] = "preprocess"
p buf # => "def preprocess(cmd)"
//}... -
String
# delete _ prefix!(prefix) -> self | nil (30074.0) -
self の先頭から破壊的に prefix を削除します。
...す。
@param prefix 先頭から削除する文字列を指定します。
@return 削除した場合は self、変化しなかった場合は nil
//emlist[][ruby]{
"hello".delete_prefix!("hel") # => "lo"
"hello".delete_prefix!("llo") # => nil
//}
@see String#delete_prefix
@see String#delete_su......ffix!
@see String#start_with?... -
String
# oct -> Integer (30074.0) -
文字列を 8 進文字列であると解釈して、整数に変換します。
...て、整数に変換します。
//emlist[例][ruby]{
p "10".oct # => 8
p "010".oct # => 8
p "8".oct # => 0
//}
oct は文字列の接頭辞 ("0", "0b", "0B", "0x", "0X") に応じて
8 進以外の変換も行います。
//emlist[例][ruby]{
p "0b10".oct # => 2
p "10".oct # => 8
p "010"......//emlist[例][ruby]{
p "-010".oct # => -8
p "-0x10".oct # => -16
p "-0b10".oct # => -2
p "1_0_1x".oct # => 65
//}
@see String#hex, String#to_i, String#to_f,
Kernel.#Integer, Kernel.#Float
逆に、数値を文字列に変換するにはKernel.#sprintf,
String#%, Integer#to_s... -
String
# casecmp(other) -> -1 | 0 | 1 | nil (30070.0) -
String#<=> と同様に文字列の順序を比較しますが、 アルファベットの大文字小文字の違いを無視します。
...
String#<=> と同様に文字列の順序を比較しますが、
アルファベットの大文字小文字の違いを無視します。
このメソッドの動作は組み込み変数 $= には影響されません。
@param other self と比較する文字列
//emlist[例][ruby]{
"aBcDe......=> 0
"aBcDeF".casecmp("abcdefg") #=> -1
"abcdef".casecmp("ABCDEF") #=> 0
//}
nil は文字列のエンコーディングが非互換の時に返されます。
//emlist[][ruby]{
"\u{e4 f6 fc}".encode("ISO-8859-1").casecmp("\u{c4 d6 dc}") #=> nil
//}
@see String#<=>, Encoding.compatible?... -
String
# gsub(pattern) -> Enumerator (30070.0) -
文字列中で pattern にマッチした部分を順番にブロックに渡し、 その実行結果で置き換えた文字列を生成して返します。 ブロックなしの場合と違い、ブロックの中からは 組み込み変数 $1, $2, $3, ... を問題なく参照できます。
...題なく参照できます。
@param pattern 置き換える文字列のパターンを表す文字列か正規表現。
文字列を指定した場合は全く同じ文字列にだけマッチする
@return 新しい文字列
//emlist[例][ruby]{
p 'abcabc'.gsub(/[bc]/) {|s|......s.upcase } #=> "aBCaBC"
p 'abcabc'.gsub(/[bc]/) { $&.upcase } #=> "aBCaBC"
//}
@see String#sub, String#scan... -
String
# <=>(other) -> -1 | 0 | 1 | nil (30068.0) -
self と other を ASCII コード順で比較して、 self が大きい時には 1、等しい時には 0、小さい時には -1 を返します。 このメソッドは Comparable モジュールのメソッドを実装するために使われます。
...返します。
@param other 文字列
@return 比較結果の整数か nil
//emlist[例][ruby]{
p "aaa" <=> "xxx" # => -1
p "aaa" <=> "aaa" # => 0
p "xxx" <=> "aaa" # => 1
p "string" <=> "stringAA" # => -1
p "string" <=> "string" # => 0
p "stringAA" <=> "string" # => 1
//}... -
String
# capitalize! -> self | nil (30068.0) -
文字列先頭の文字を大文字に、残りを小文字に変更します。 ただし、アルファベット以外の文字は位置に関わらず変更しません。
...
@return capitalize! は self を変更して返しますが、
変更が起こらなかった場合は nil を返します。
//emlist[例][ruby]{
str = "foobar"
str.capitalize!
p str # => "Foobar"
str = "fooBAR"
str.capitalize!
p str # => "Foobar"
//}
@see String#capitalize, String......#upcase!,
String#downcase!, String#swapcase!... -
String
# end _ with?(*strs) -> bool (30068.0) -
self の末尾が strs のいずれかであるとき true を返します。
...ずれかであるとき true を返します。
@param strs パターンを表す文字列 (のリスト)
//emlist[例][ruby]{
"string".end_with?("ing") # => true
"string".end_with?("str") # => false
"string".end_with?("str", "ing") # => true
//}
@see String#start_with?... -
String
# start _ with?(*strs) -> bool (30068.0) -
self の先頭が strs のいずれかであるとき true を返します。
...れかであるとき true を返します。
@param strs パターンを表す文字列 (のリスト)
//emlist[例][ruby]{
"string".start_with?("str") # => true
"string".start_with?("ing") # => false
"string".start_with?("ing", "str") # => true
//}
@see String#end_with?... -
String
# sub!(pattern) {|matched| . . . . } -> self | nil (30063.0) -
文字列中で pattern にマッチした最初の部分をブロックに渡し、 その評価結果へ破壊的に置き換えます。
...す。
@param pattern 置き換える文字列のパターンを表す文字列か正規表現。
文字列を指定した場合は全く同じ文字列にだけマッチする
@return 置換した場合は self、置換しなかった場合は nil
//emlist[例][ruby]{
str = '......abcabc'
str.sub!(/b/) {|s| s.upcase }
p str #=> "aBcabc"
str = 'abcabc'
str.sub!(/b/) { $&.upcase }
p str #=> "aBcabc"
//}
@see String#gsub...