99件ヒット
[1-99件を表示]
(0.020秒)
別のキーワード
ライブラリ
- ビルトイン (99)
キーワード
-
define
_ method (22) -
instance
_ methods (11) -
method
_ added (11) -
private
_ instance _ methods (11) -
protected
_ instance _ methods (11) -
public
_ instance _ method (11) -
public
_ instance _ methods (11)
検索結果
先頭5件
-
Module
# instance _ method(name) -> UnboundMethod (27139.0) -
self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
... Module#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
# public _ instance _ method(name) -> UnboundMethod (15133.0) -
self の public インスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
...として与えると発生します。
//emlist[例][ruby]{
Kernel.public_instance_method(:object_id) #=> #<UnboundMethod: Kernel#object_id>
Kernel.public_instance_method(:p) # method `p' for module `Kernel' is private (NameError)
//}
@see Module#instance_method,Object#public_method... -
Module
# private _ instance _ methods(inherited _ too = true) -> [Symbol] (15120.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]
//}... -
Module
# protected _ instance _ methods(inherited _ too = true) -> [Symbol] (15108.0) -
そのモジュールで定義されている protected メソッド名 の一覧を配列で返します。
...そのモジュールで定義されている protected メソッド名
の一覧を配列で返します。
@param inherited_too false を指定するとそのモジュールで定義されているメソッドのみ返します。
@see Object#protected_methods, Module#instance_methods... -
Module
# public _ instance _ methods(inherited _ too = true) -> [Symbol] (15108.0) -
そのモジュールで定義されている public メソッド名 の一覧を配列で返します。
...そのモジュールで定義されている public メソッド名
の一覧を配列で返します。
@param inherited_too false を指定するとそのモジュールで定義されているメソッドのみ返します。
@see Object#public_methods, Module#instance_methods... -
Module
# instance _ methods(inherited _ too = true) -> [Symbol] (15102.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_foo]......ar.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_methods(... -
Module
# define _ method(name) { . . . } -> Symbol (9008.0) -
インスタンスメソッド name を定義します。
...。
@raise TypeError method に同じクラス、サブクラス、モジュール以外のメソッ
ドを指定した場合に発生します。
//emlist[例][ruby]{
class Foo
def foo() p :foo end
define_method(:bar, instance_method(:foo))
end
Foo.new.bar # => :foo
//}... -
Module
# define _ method(name , method) -> Symbol (9008.0) -
インスタンスメソッド name を定義します。
...。
@raise TypeError method に同じクラス、サブクラス、モジュール以外のメソッ
ドを指定した場合に発生します。
//emlist[例][ruby]{
class Foo
def foo() p :foo end
define_method(:bar, instance_method(:foo))
end
Foo.new.bar # => :foo
//}... -
Module
# method _ added(name) -> () (9008.0) -
メソッド name が追加された時にインタプリタがこのメソッドを呼び出します。
...加されたメソッドの名前が Symbol で渡されます。
//emlist[例][ruby]{
class Foo
def Foo.method_added(name)
puts "method \"#{name}\" was added"
end
def foo
end
define_method :bar, instance_method(:foo)
end
# => method "foo" was added
# method "bar" was added
//}...