るりまサーチ

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

ライブラリ

検索結果

<< < ... 2 3 4 5 6 ... > >>

Object#instance_of?(klass) -> bool (2.0)

オブジェクトがクラス klass の直接のインスタンスである時真を返します。

...常に obj.kind_of?(c) も成立します。

@param klass Classかそのサブクラスのインスタンスです。

//emlist[][ruby]{
class C < Object
end
class S < C
end

obj = S.new
p obj.instance_of?(S) # true
p obj.instance_of?(C) # false
//}

@see Object#kind_of?,Object#class...

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

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

..., @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 (2.0)

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

...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#instance_variable_set(var, value) -> object (2.0)

オブジェクトのインスタンス変数 var に値 value を設定します。

...value を返します。

//emlist[][ruby]{
obj = Object.new
p obj.instance_variable_set("@foo", 1) #=> 1
p obj.instance_variable_set(:@foo, 2) #=> 2
p obj.instance_variable_get(:@foo) #=> 2
//}

@see Object#instance_variable_get,Object#instance_variables,Object#instance_variable_defined?...

Object#instance_variables -> [Symbol] (2.0)

オブジェクトのインスタンス変数名をシンボルの配列として返します。

...スタンス変数名をシンボルの配列として返します。

//emlist[][ruby]{
obj = Object.new
obj.instance_eval { @foo, @bar = nil }
p obj.instance_variables

#=> [:@foo, :@bar]
//}

@see Object#instance_variable_get, Kernel.#local_variables, Kernel.#global_variables, Module.constants, M...

絞り込み条件を変える

Object#is_a?(mod) -> bool (2.0)

オブジェクトが指定されたクラス mod かそのサブクラスのインスタンスであるとき真を返します。

...ードしたクラスかそのサブクラス
のインスタンスである場合にも真を返します。
Module#includeだけではなく、Object#extendやModule#prependに
よってサブクラスのインスタンスになる場合も含みます。
上記のいずれでもない場合に fa...
...です。

//emlist[][ruby]{
module M
end
class C < Object
include M
end
class S < C
end

obj = S.new
p obj.is_a?(S) # true
p obj.is_a?(C) # true
p obj.is_a?(Object) # true
p obj.is_a?(M) # true
p obj.is_a?(Hash) # false
//}

@see Object#instance_of?,Module#===,Object#class...

Object#itself -> object (2.0)

self を返します。

...self を返します。

//emlist[][ruby]{
string = 'my string' # => "my string"
string.itself.object_id == string.object_id # => true
//}...

Object#kind_of?(mod) -> bool (2.0)

オブジェクトが指定されたクラス mod かそのサブクラスのインスタンスであるとき真を返します。

...ードしたクラスかそのサブクラス
のインスタンスである場合にも真を返します。
Module#includeだけではなく、Object#extendやModule#prependに
よってサブクラスのインスタンスになる場合も含みます。
上記のいずれでもない場合に fa...
...です。

//emlist[][ruby]{
module M
end
class C < Object
include M
end
class S < C
end

obj = S.new
p obj.is_a?(S) # true
p obj.is_a?(C) # true
p obj.is_a?(Object) # true
p obj.is_a?(M) # true
p obj.is_a?(Hash) # false
//}

@see Object#instance_of?,Module#===,Object#class...

Object#marshal_dump -> object (2.0)

Marshal.#dump を制御するメソッドです。

...定義されていてもマーシャルできるようになります
(特異メソッドの情報が自動的に dump されるようになるわけではなく、
marshal_dump/marshal_load によりそれを実現する余地があるということです)。

@see Object#marshal_load, Marshal...
<< < ... 2 3 4 5 6 ... > >>