るりまサーチ

最速Rubyリファレンスマニュアル検索!
55件ヒット [1-55件を表示] (0.025秒)
トップページ > クラス:Object[x] > クエリ:ri[x] > クエリ:initialize[x]

別のキーワード

  1. ri generate
  2. ri description
  3. rdoc/generator/ri initialize
  4. rdoc/generator/ri ri

ライブラリ

キーワード

検索結果

Object#instance_variable_defined?(var) -> bool (6107.0)

インスタンス変数 var が定義されていたら真を返します。

...def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
p fred.instance_variable_defined?(:@a) #=> true
p fred.instance_variable_defined?("@b") #=> true
p fred.instance_variable_defined?("@c") #=> false
//}

@see Object#instance_variable_get,Object#instance_variable_...
...set,Object#instance_variables...

Object#instance_variable_get(var) -> object | nil (6107.0)

オブジェクトのインスタンス変数の値を取得して返します。

...ass Foo
def initialize
@foo = 1
end
end

obj = Foo.new
p obj.instance_variable_get("@foo") #=> 1
p obj.instance_variable_get(:@foo) #=> 1
p obj.instance_variable_get(:@bar) #=> nil
//}

@see Object#instance_variable_set,Object#instance_variables,Object#instance_variable_defined...

Object#_dump(limit) -> String (107.0)

Marshal.#dump において出力するオブジェクトがメソッド _dump を定義している場合には、そのメソッドの結果が書き出されます。

...ッド _dump
を定義している場合には、そのメソッドの結果が書き出されます。

バージョン1.8.0以降ではObject#marshal_dump, Object#marshal_loadの使用
が推奨されます。 Marshal.dump するオブジェクトが _dump と marshal_dump の両方の
メソッ...
...数です。
@return オブジェクトを文字列化したものを返すように定義すべきです。

//emlist[][ruby]{
class Foo
def initialize(arg)
@foo = arg
end
def _dump(limit)
Marshal.dump(@foo, limit)
end
def self._load(obj)
p obj
Foo.new(Marshal.load(obj))...
...い場合や拡張ライブラリで定義し
たクラスのインスタンスがインスタンス変数以外に情報を保持する場合に
利用します。(例えば、クラス Time は、_dump/_load を定義して
います)

@see Object#marshal_dump, Object#marshal_load, Class#_load...

Object#inspect -> String (107.0)

オブジェクトを人間が読める形式に変換した文字列を返します。

...変数の名前、値の組を元にした文字列を返します。

//emlist[][ruby]{
class Foo
end
Foo.new.inspect # => "#<Foo:0x0300c868>"

class Bar
def initialize
@bar = 1
end
end
Bar.new.inspect # => "#<Bar:0x0300c868 @bar=1>"
//}

@see Kernel.#p...

Object#to_s -> String (107.0)

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

...の文字列表現を返します。

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

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

put...
...s it #=> #<Foo:0x2b69110>

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

puts it #=> Class:Foo Number:40
//}

@see Object#to_str,Kernel.#String...

絞り込み条件を変える