るりまサーチ

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

別のキーワード

  1. csv instance
  2. prime instance
  3. singleton instance
  4. syslog instance
  5. _builtin instance_eval

検索結果

<< 1 2 > >>

Object#class -> Class (18263.0)

レシーバのクラスを返します。

...レシーバのクラスを返します。

//emlist[][ruby]{
p "ruby".class #=> String
p 100.class #=> Integer
p ARGV.class #=> Array
p self.class #=> Object
p Class.class #=> Class
p Kernel.class #=> Module
//}

@see Class#superclass,Object#kind_of?,Object#instance_of?...

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

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

...

obj.instance_of?(c) が成立する時には、常に 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 (6144.0)

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

...by]{
class
Fred
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#in...
...stance_variable_set,Object#instance_variables...

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

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

...[ruby]{
class
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_variab...

Object#remove_instance_variable(name) -> object (6132.0)

オブジェクトからインスタンス変数 name を取り除き、そのインス タンス変数に設定されていた値を返します。

...ない場合に発生します。

//emlist[][ruby]{
class
Foo
def foo
@foo = 1
p remove_instance_variable(:@foo) #=> 1
p remove_instance_variable(:@foo) # instance variable @foo not defined (NameError)
end
end
Foo.new.foo
//}

@see Module#remove_class_variable,Module#remove_const...

絞り込み条件を変える

Object#instance_variables -> [Symbol] (6126.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, Module#constants, Module#class_variables...

Object#methods(include_inherited = true) -> [Symbol] (49.0)

そのオブジェクトに対して呼び出せるメソッド名の一覧を返します。 このメソッドは public メソッドおよび protected メソッドの名前を返します。

...

ただし特別に、引数が偽の時は Object#singleton_methods(false) と同じになっています。


@param include_inherited 引数が偽の時は Object#singleton_methods(false) と同じになります。

//emlist[例1][ruby]{
class
Parent
private; def private_parent() end...
...; def protected_parent() end
public; def public_parent() end
end

class
Foo < Parent
private; def private_foo() end
protected; def protected_foo() end
public; def public_foo() end
end

obj = Foo.new
class
<<obj
private; def private_singleton() end
protected; def p...
...
# いるが、Object のインスタンスメソッドは一覧から排除している。
p obj.methods(true) - Object.instance_methods(true)
p obj.public_methods(true) - Object.public_instance_methods(true)
p obj.private_methods(true) - Object.private_instance_methods(true)
p ob...

Object#initialize_copy(obj) -> object (37.0)

(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。

...は self を obj の内容で置き換えます。ただ
し、self のインスタンス変数や特異メソッドは変化しません。
Object
#clone, Object#dupの内部で使われています。

initialize_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに...
...ます。
@see Object#clone,Object#dup

以下に例として、dup や clone がこのメソッドをどのように利用しているかを示します。

obj.dup は、新たに生成したオブジェクトに対して
initialize_copy を呼び

//emlist[][ruby]{
obj2 = obj.class.allocate
obj2....
...j = Object.new
class
<<obj
attr_accessor :foo
def bar
:bar
end
end

def check(obj)
puts "instance variables: #{obj.inspect}"
puts "tainted?: #{obj.tainted?}"
print "singleton methods: "
begin
p obj.bar
rescue NameError
p $!
end
end

obj.foo = 1
obj.taint

check Object.n...
...//emlist[][ruby]{
obj = Object.new
class
<<obj
attr_accessor :foo
def bar
:bar
end
end

def check(obj)
puts "instance variables: #{obj.inspect}"
print "singleton methods: "
begin
p obj.bar
rescue NameError
p $!
end
end

obj.foo = 1

check Object.new.send(:initialize_cop...

Object#respond_to?(name, include_all = false) -> bool (31.0)

オブジェクトがメソッド name を持つとき真を返します。

...されたメソッドで NotImplementedError が発生する場合は true を返します。

メソッドが定義されていない場合は、Object#respond_to_missing? を呼
び出してその結果を返します。

@param name Symbol または文字列で指定するメソッド名です。...
...事になります。

//emlist[][ruby]{
class
F
def hello
"Bonjour"
end
end

class
D
private
def hello
"Guten Tag"
end
end
list = [F.new,D.new]

list.each{|it| puts it.hello if it.respond_to?(:hello)}
#=> Bonjour

list.each{|it| it.instance_eval("puts hello if it.respond_to?(:hell...
...ate_method
raise NotImplementedError.new
end

def finish
puts "finish"
end
end

class
ImplTemplateMethod
include Template
def template_method
"implement template_method"
end
end

class
NotImplTemplateMethod
include Template

# not implement template_method
end

puts ImplT...

Object#===(other) -> bool (25.0)

case 式で使用されるメソッドです。d:spec/control#case も参照してください。

...ドは case 式での振る舞いを考慮して、
各クラスの性質に合わせて再定義すべきです。

デフォルトでは内部で Object#== を呼び出します。

when 節の式をレシーバーとして === を呼び出すことに注意してください。

また Enumerable...
...g}"
when String
"Instance of String class. But don't hit."
else
"unknown"
end
end

puts check([]) #=> unknown
puts check("mash-up in Ruby on Rails") #=> instance of String class. But not hit...
puts check("<Ruby's world>") #=> hit! <Ruby's world>
//}

@see Object#==, Range#===, Module#...

絞り込み条件を変える

<< 1 2 > >>