るりまサーチ (Ruby 2.1.0)

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

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

ライブラリ

クラス

キーワード

検索結果

Object#to_str -> String (78343.0)

オブジェクトの String への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。

オブジェクトの String への暗黙の変換が必要なときに内部で呼ばれます。
デフォルトでは定義されていません。

説明のためここに記載してありますが、
このメソッドは実際には Object クラスには定義されていません。
必要に応じてサブクラスで定義すべきものです。

このメソッドを定義する条件は、
* 文字列が使われるすべての場面で代置可能であるような、
* 文字列そのものとみなせるようなもの
という厳しいものになっています。

//emlist[][ruby]{
class Foo
def to_str
'Edition'
end
end

it = Foo.new...

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

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

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

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

@param other 任意のオブジェクト
@return true か false

//emlist[例][ruby]{
stringlike = Object.new

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

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

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

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

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

@param other 任意のオブジェクト
@return true か false

//emlist[例][ruby]{
stringlike = Object.new

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

Object#to_s -> String (24040.0)

オブジェクトの文字列表現を返します。

オブジェクトの文字列表現を返します。

Kernel.#print や Kernel.#sprintf は文字列以外の
オブジェクトが引数に渡された場合このメソッドを使って文字列に変換し
ます。

//emlist[][ruby]{
class Foo
def initialize num
@num = num
end
end
it = Foo.new(40)

puts it #=> #<Foo:0x2b69110>

class Foo
def to_s
"Class:Foo Number:#{@num}"
end
end

puts it #=> Cla...