るりまサーチ

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

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. kernel p
  5. rsa p

ライブラリ

キーワード

検索結果

String#to_str -> String (15139.0)

self を返します。

...self を返します。

//emlist[例][ruby]{
p
"str".to_s # => "str"
p
"str".to_str # => "str"
//}

このメソッドは、文字列を他のクラスのインスタンスと混ぜて処理したいときに有効です。
例えば返り値が文字列か nil であるメソッド some_met...
...hod があるとき、
to_s メソッドを使うと以下のように統一的に処理できます。

//emlist[例][ruby]{
# some_method(5).downcase だと返り値が nil のときに
# エラーになるので to_s をはさむ
p
some_method(5).to_s.downcase
//}...

String#<=>(other) -> -1 | 0 | 1 | nil (50.0)

self と other を ASCII コード順で比較して、 self が大きい時には 1、等しい時には 0、小さい時には -1 を返します。 このメソッドは Comparable モジュールのメソッドを実装するために使われます。

...ッドは Comparable モジュールのメソッドを実装するために使われます。

other が文字列でない場合、
other.to_str と other.<=> が定義されていれば
0 - (other <=> self) の結果を返します。
そうでなければ nil を返します。

@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 (50.0)

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

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

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

@param ot...
...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 (50.0)

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

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

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

@param ot...
...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#to_s -> String (39.0)

self を返します。

...self を返します。

//emlist[例][ruby]{
p
"str".to_s # => "str"
p
"str".to_str # => "str"
//}

このメソッドは、文字列を他のクラスのインスタンスと混ぜて処理したいときに有効です。
例えば返り値が文字列か nil であるメソッド some_met...
...hod があるとき、
to_s メソッドを使うと以下のように統一的に処理できます。

//emlist[例][ruby]{
# some_method(5).downcase だと返り値が nil のときに
# エラーになるので to_s をはさむ
p
some_method(5).to_s.downcase
//}...

絞り込み条件を変える