るりまサーチ

最速Rubyリファレンスマニュアル検索!
1988件ヒット [1-100件を表示] (0.034秒)
トップページ > ライブラリ:ビルトイン[x] > クラス:String[x]

キーワード

検索結果

<< 1 2 3 ... > >>

String#%(args) -> String (3.0)

printf と同じ規則に従って args をフォーマットします。

...sprintf("%c", 'a') #=> "a"
//}

フラグ `-' と幅 の指定だけが意味を持ちます。

: s

文字列を出力します。

引数が String オブジェクトでなければ to_s メソッドにより文字列化
したものを引数として扱います。

: p

Object#inspect の...

String#*(times) -> String (3.0)

文字列の内容を times 回だけ繰り返した新しい文字列を作成して返します。

文字列の内容を times 回だけ繰り返した新しい文字列を作成して返します。

@param times 整数
@return self を times 回繰り返した新しい文字列

@raise ArgumentError 引数に負数を指定したときに発生します。

//emlist[例][ruby]{
p "str" * 3 # => "strstrstr"

str = "abc"
p str * 4 # => "abcabcabcabc"
p str * 0 # => ""
p str # => "abc" (変化なし)
//}

String#+(other) -> String (3.0)

文字列と other を連結した新しい文字列を返します。

...er を連結した新しい文字列を返します。

@param other 文字列
@return self と other を連結した文字列

//emlist[例][ruby]{
p "str" + "ing" # => "string"

a = "abc"
b = "def"
p a + b # => "abcdef"
p a # => "abc" (変化なし)
p b # => "def"
//}...

String#+@ -> String | self (3.0)

self が freeze されている文字列の場合、元の文字列の複製を返します。 freeze されていない場合は self を返します。

...の場合、元の文字列の複製を返します。
freeze されていない場合は self を返します。

//emlist[例][ruby]{
# frozen_string_literal: false

original_text = "text"
unfrozen_text = +original_text
unfrozen_text.frozen? # => false
original_text == unfrozen_tex...
...t # => true
original_text.equal?(unfrozen_text) # => true

original_text = "text".freeze
unfrozen_text = +original_text
unfrozen_text.frozen? # => false
original_text == unfrozen_text # => true
original_text.equal?(unfrozen_text) # => false
//}

@see String#-@...

String#-@ -> String | self (3.0)

self が freeze されている文字列の場合、self を返します。 freeze されていない場合は元の文字列の freeze された (できる限り既存の) 複製を返します。

...されていない場合は元の文字列の freeze された (できる限り既存の) 複製を返します。

//emlist[例][ruby]{
# frozen_string_literal: false

original_text = "text"
frozen_text = -original_text
frozen_text.frozen? # => true
original_text == frozen_text...
...# => true
original_text.equal?(frozen_text) # => false

original_text = "text".freeze
frozen_text = -original_text
frozen_text.frozen? # => true
original_text == frozen_text # => true
original_text.equal?(frozen_text) # => true
//}

@see String#+@...

絞り込み条件を変える

String#<<(other) -> self (3.0)

self に文字列 other を破壊的に連結します。 other が 整数である場合は other.chr(self.encoding) 相当の文字を末尾に追加します。

...追加します。

self を返します。

@param other 文字列もしくは 0 以上の整数

//emlist[例][ruby]{
str = "string"
str.concat "XXX"
p str # => "stringXXX"

str << "YYY"
p str # => "stringXXXYYY"

str << 65 # 文字AのASCIIコード
p str # => "stringXXXYYYA"
//}...

String#<=>(other) -> -1 | 0 | 1 | nil (3.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#==(other) -> bool (3.0)

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

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

other が文字列でない場合、
other.to_str が定義されていれば
other == self の結果を返します。(ただし、 other.to_str は実行されません。)
そうでなければ false...
...st[例][ruby]{
string
like = Object.new

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

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

def stringlike.to_str
raise
end

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

@see String#eql?...

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

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

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

other が文字列でない場合、
other.to_str が定義されていれば
other == self の結果を返します。(ただし、 other.to_str は実行されません。)
そうでなければ false...
...st[例][ruby]{
string
like = Object.new

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

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

def stringlike.to_str
raise
end

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

@see String#eql?...

String#=~(other) -> Integer | nil (3.0)

正規表現 other とのマッチを行います。 マッチが成功すればマッチした位置のインデックスを、そうでなければ nil を返します。

...が設定されます。

@param other 正規表現もしくは =~ メソッドを持つオブジェクト
@raise TypeError other が文字列の場合に発生します。

//emlist[例][ruby]{
p "string" =~ /str/ # => 0
p "string" =~ /not/ # => nil
p "abcfoo" =~ /foo/ # => 3
//}...

絞り込み条件を変える

<< 1 2 3 ... > >>