44件ヒット
[1-44件を表示]
(0.299秒)
キーワード
- methods (11)
-
private
_ instance _ methods (11) -
undef
_ method (11)
検索結果
先頭4件
-
Module
# instance _ methods(inherited _ too = true) -> [Symbol] (26230.0) -
そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返します。
...oo() end
protected; def protected_foo() end
public; def public_foo() end
end
# あるクラスのインスタンスメソッドの一覧を得る
p Foo.instance_methods(false)
p Foo.public_instance_methods(false)
p Foo.private_instance_methods(false)
p Foo.protected_instance_methods(fal......class Bar < Foo
end
//}
実行結果
[:protected_foo, :public_foo]
[:public_foo]
[:private_foo]
[:protected_foo]
//emlist[例2][ruby]{
class Bar
private; def private_foo() end
protected; def protected_foo() end
public; def public_foo() end
end
# あるクラ......r.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(t... -
Module
# private _ instance _ methods(inherited _ too = true) -> [Symbol] (14158.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]
//}... -
Object
# methods(include _ inherited = true) -> [Symbol] (8105.0) -
そのオブジェクトに対して呼び出せるメソッド名の一覧を返します。 このメソッドは public メソッドおよび protected メソッドの名前を返します。
...() end
protected; 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 protected_singleton() end
public; def public_singleton() end
end
# あるオブジェクトの応答できるメソッドの一覧を得る。
p obj.methods(false)
p obj.public_methods(false)
p obj.private_methods(false)
p obj.protected_methods(false)
# 実行結果
[:......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 obj.protected_methods(true) - Object.protected_instance_methods(true)
# 実行結果
[:protected_s... -
Module
# undef _ method(*name) -> self (8099.0) -
このモジュールのインスタンスメソッド name を未定義にします。
...y]{
class A
def ok
puts 'A'
end
end
class B < A
def ok
puts 'B'
end
end
B.new.ok # => B
# undef_method の場合はスーパークラスに同名のメソッドがあっても
# その呼び出しはエラーになる
class B
undef_method :ok
end
B.new.ok # => NameError
# re......remove_method :ok
end
B.new.ok # => A
//}
また、undef 文と undef_method の違いは、
メソッド名を String または Symbol で与えられることです。
//emlist[例][ruby]{
module M1
def foo
end
def self.moo
undef foo
end
end
M1.instance_methods false #=> ["foo"]......M1.moo
M1.instance_methods false #=> []
module M2
def foo
end
def self.moo
undef_method :foo
end
end
M2.instance_methods false #=> ["foo"]
M2.moo
M2.instance_methods false #=> []
//}...