るりまサーチ

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

別のキーワード

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

モジュール

オブジェクト

キーワード

検索結果

<< 1 2 3 ... > >>

Digest::Instance (18000.0)

Module#instance_methods(inherited_too = true) -> [Symbol] (6173.0)

そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返します。

...) end
end

# あるクラスのインスタンスメソッドの一覧を得る
p Foo.instance_methods(false)
p Foo.public_instance_methods(false)
p Foo.private_instance_methods(false)
p Foo.protected_instance_methods(false)

class Bar < Foo
end
//}

実行結果

[:protected_foo, :public_fo...
...p Bar.instance_methods(true) - Object.instance_methods(true)
p Bar.public_instance_methods(true) - Object.public_instance_methods(true)
p Bar.private_instance_methods(true) - Object.private_instance_methods(true)
p Bar.protected_instance_methods(true) - Object.protected_instance_metho...

BasicObject#instance_eval {|obj| ... } -> object (6168.0)

オブジェクトのコンテキストで文字列 expr またはオブジェクト自身をブロックパラメータとするブロックを 評価してその結果を返します。

...では instance_eval の外側のスコープと、ブロックの評価ではそのブロックの外側のスコープと、共有します。

メソッド定義の中で instance_eval でメソッドを定義した場合は、囲むメソッドが実行されたときに
初めて instance_eval...
...ド定義のネストと同じです。
d:spec/def#nest_method を参照してください。

BasicObject を継承して作ったクラス内で instance_eval する場合はトップレベルの定数や Kernel モジュールに定義されているメソッドは見えません。
これは、...
...'secret'
end
end

some = Foo.new 'XXX'
some.instance_eval{p @key} #=> "XXX"
some.instance_eval{do_fuga } #=> "secret" # private メソッドも呼び出せる

some.instance_eval 'raise' # ..:10: (eval):1: (RuntimeError)
messg = 'unknown'
some.instance_eval 'raise messg','file.rb',999 # file.rb:9...

BasicObject#instance_eval(expr, filename = "(eval)", lineno = 1) -> object (6168.0)

オブジェクトのコンテキストで文字列 expr またはオブジェクト自身をブロックパラメータとするブロックを 評価してその結果を返します。

...では instance_eval の外側のスコープと、ブロックの評価ではそのブロックの外側のスコープと、共有します。

メソッド定義の中で instance_eval でメソッドを定義した場合は、囲むメソッドが実行されたときに
初めて instance_eval...
...ド定義のネストと同じです。
d:spec/def#nest_method を参照してください。

BasicObject を継承して作ったクラス内で instance_eval する場合はトップレベルの定数や Kernel モジュールに定義されているメソッドは見えません。
これは、...
...'secret'
end
end

some = Foo.new 'XXX'
some.instance_eval{p @key} #=> "XXX"
some.instance_eval{do_fuga } #=> "secret" # private メソッドも呼び出せる

some.instance_eval 'raise' # ..:10: (eval):1: (RuntimeError)
messg = 'unknown'
some.instance_eval 'raise messg','file.rb',999 # file.rb:9...

Object#instance_variable_defined?(var) -> bool (6137.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 (6137.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 (6137.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?...

Module#instance_method(name) -> UnboundMethod (6131.0)

self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。

...ule#public_instance_method, Object#method

//emlist[例][ruby]{
class Interpreter
def do_a() print "there, "; end
def do_d() print "Hello "; end
def do_e() print "!\n"; end
def do_v() print "Dave"; end
Dispatcher = {
"a" => instance_method(:do_a),
"d" => instance_method(:do...
..._d),
"e" => instance_method(:do_e),
"v" => instance_method(:do_v)
}
def interpret(string)
string.each_char {|b| Dispatcher[b].bind(self).call }
end
end

interpreter = Interpreter.new
interpreter.interpret('dave')
# => Hello there, Dave!
//}...

Module#private_instance_methods(inherited_too = true) -> [Symbol] (6119.0)

そのモジュールで定義されている private メソッド名 の一覧を配列で返します。

...@see Object#private_methods, Module#instance_methods

//emlist[例][ruby]{
module Foo
def foo; end
private def bar; end
end

module Bar
include Foo

def baz; end
private def qux; end
end

Bar.private_instance_methods # => [:qux, :bar]
Bar.private_instance_methods(false) # => [:qux]
//}...
<< 1 2 3 ... > >>