るりまサーチ

最速Rubyリファレンスマニュアル検索!
2131件ヒット [1301-1400件を表示] (0.121秒)

別のキーワード

  1. fiddle ruby_free
  2. rbconfig ruby
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

キーワード

検索結果

<< < ... 12 13 14 15 16 ... > >>

String#sub!(pattern, replace) -> self | nil (12172.0)

文字列中で pattern にマッチした最初の部分を文字列 replace へ破壊的に置き換えます。

...文字列中で pattern にマッチした最初の部分を文字列 replace へ破壊的に置き換えます。

置換文字列 replace 中の \& と \0 はマッチした部分文字列に、
\1 ... \9 は n 番目の括弧の内容に置き換えられます。
置換文字列内では \`、\...
...ます。

@param pattern 置き換える文字列のパターンを表す文字列か正規表現。
文字列を指定した場合は全く同じ文字列にだけマッチする
@param replace pattern で指定した文字列と置き換える文字列
@return 置換した...
...場合は nil

//emlist[例][ruby]{
buf = "String-String"
buf.sub!(/in./, "!!")
p buf # => "Str!!-String"

buf = "String.String"
buf.sub!(/in./, '<<\&>>')
p buf # => "Str<<ing>>-String"
//}

注意:

引数 replace の中で $1 を使うことはできません。
r
eplace は sub メソッドの...

String#lines(rs = $/, chomp: false) {|line| ... } -> self (12169.0)

文字列中の各行を文字列の配列で返します。(self.each_line.to_a と同じです)

...[][ruby]{
"aa\nbb\ncc\n".lines # => ["aa\n", "bb\n", "cc\n"]
//}

行の区切りは rs に指定した文字列で、 そのデフォルト値は変数 $/ の値です。
各 line には区切りの文字列も含みます。

r
s に nil を指定すると行区切りなしとみなします。 rs...
...chomp に true を指定すると、分割した各行の末尾から rs を取り除きます。

//emlist[][ruby]{
"hello\nworld\n".lines # => ["hello\n", "world\n"]
"hello\nworld\n".lines(chomp: true) # => ["hello", "world"]
//}

@param rs 行末を示す文字列

@param chomp 分...
...た各行に対して String#chomp と同等の結果を得
る場合は true を、そうでない場合は false で指定します。
省略した場合は false を指定したとみなされます。

ブロックが指定された場合は String#each_line と同じ...

String#gsub!(pattern, replace) -> self | nil (12167.0)

文字列中で pattern にマッチする部分全てを文字列 replace に破壊的に置き換えます。

...文字列中で pattern にマッチする部分全てを文字列 replace に破壊的に置き換えます。

置換文字列 replace 中の \& と \0 はマッチした部分文字列に、
\1 ... \9 は n 番目の括弧の内容に置き換えられます。
置換文字列内では \`、\'...
...ます。

@param pattern 置き換える文字列のパターンを表す文字列か正規表現。
文字列を指定した場合は全く同じ文字列にだけマッチする
@param replace pattern で指定した文字列と置き換える文字列
@return 置換した...
...合は nil

//emlist[例][ruby]{
buf = "String-String"
buf.gsub!(/in./, "!!")
p buf # => "Str!!-Str!!"

buf = "String.String"
buf.gsub!(/in./, '<<\&>>')
p buf # => "Str<<ing>>-Str<<ing>>"
//}

注意:

引数 replace の中で $1 を使うことはできません。
r
eplace は gsub メソッド...

String#==(other) -> bool (12166.0)

other が文字列の場合、String#eql? と同様に文字列の内容を比較します。

...other が文字列の場合、String#eql? と同様に文字列の内容を比較します。

other が文字列でない場合、
other.to_str が定義されていれば
other == self の結果を返します。(ただし、 other.to_str は実行されません。)
そうでなければ false...
...ram other 任意のオブジェクト
@return true か false

//emlist[例][ruby]{
string
like = Object.new

def stringlike.==(other)
"string" == other
end

p "string".eql?(stringlike) #=> false
p "string" == stringlike #=> false

def stringlike.to_str
r
aise
end

p "string".eql?(str...
...inglike) #=> false
p "string" == stringlike #=> true
//}

@see String#eql?...

String#===(other) -> bool (12166.0)

other が文字列の場合、String#eql? と同様に文字列の内容を比較します。

...other が文字列の場合、String#eql? と同様に文字列の内容を比較します。

other が文字列でない場合、
other.to_str が定義されていれば
other == self の結果を返します。(ただし、 other.to_str は実行されません。)
そうでなければ false...
...ram other 任意のオブジェクト
@return true か false

//emlist[例][ruby]{
string
like = Object.new

def stringlike.==(other)
"string" == other
end

p "string".eql?(stringlike) #=> false
p "string" == stringlike #=> false

def stringlike.to_str
r
aise
end

p "string".eql?(str...
...inglike) #=> false
p "string" == stringlike #=> true
//}

@see String#eql?...

絞り込み条件を変える

String#match?(regexp, pos = 0) -> bool (12162.0)

regexp.match?(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match? を参照してください。

...
r
egexp.match?(self, pos) と同じです。
r
egexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match? を参照してください。

//emlist[例][ruby]{
"Ruby".match?(/R.../) #=> true
"Ruby".match?(/R.../, 1) #=> false
"Ruby".match?(/P.../) #=>...
...false
$& #=> nil
//}

@see Regexp#match?, Symbol#match?...

String#oct -> Integer (12162.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 (12154.0)

String#<=> と同様に文字列の順序を比較しますが、 アルファベットの大文字小文字の違いを無視します。

...
String
#<=> と同様に文字列の順序を比較しますが、
アルファベットの大文字小文字の違いを無視します。

このメソッドの動作は組み込み変数 $= には影響されません。

String
#casecmp? と違って大文字小文字の違いを無視するの...
...
Unicode 全体ではなく、A-Z/a-z だけです。

@param other self と比較する文字列

//emlist[例][ruby]{
"aBcDeF".casecmp("abcde") #=> 1
"aBcDeF".casecmp("abcdef") #=> 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#lines(rs = $/) {|line| ... } -> self (12151.0)

文字列中の各行を文字列の配列で返します。(self.each_line.to_a と同じです)

...[][ruby]{
"aa\nbb\ncc\n".lines # => ["aa\n", "bb\n", "cc\n"]
//}

行の区切りは rs に指定した文字列で、 そのデフォルト値は変数 $/ の値です。
各 line には区切りの文字列も含みます。

r
s に nil を指定すると行区切りなしとみなします。 rs...
...(つまり空行で分割します)。


@param rs 行末を示す文字列


ブロックが指定された場合は String#each_line と同じように動作します。

Ruby
2.6 までは deprecated の警告が出ますが、Ruby 2.7 で警告は削除されました。

@see String#each_line...

String#bytes -> [Integer] (12150.0)

文字列の各バイトを数値の配列で返します。(self.each_byte.to_a と同じです)

...と同じです)

//emlist[例][ruby]{
"str".bytes # => [115, 116, 114]
//}

ブロックが指定された場合は String#each_byte と同じように動作します。

Ruby
2.6 までは deprecated の警告が出ますが、Ruby 2.7 で警告は削除されました。

@see String#each_byte...

絞り込み条件を変える

String#codepoints -> [Integer] (12150.0)

文字列の各コードポイントの配列を返します。(self.each_codepoint.to_a と同じです)

...ist[例][ruby]{
#coding:UTF-8
"hello わーるど".codepoints
# => [104, 101, 108, 108, 111, 32, 12431, 12540, 12427, 12393]
//}

ブロックが指定された場合は String#each_codepoint と同じように動作します。

Ruby
2.6 までは deprecated の警告が出ますが、Ruby 2.7 で...
...警告は削除されました。

@see String#each_codepoint...
<< < ... 12 13 14 15 16 ... > >>