121件ヒット
[1-100件を表示]
(0.022秒)
別のキーワード
ライブラリ
- ビルトイン (121)
キーワード
-
define
_ singleton _ method (22) -
initialize
_ copy (11) - method (11)
- methods (11)
-
private
_ methods (11) -
protected
_ methods (11) -
public
_ methods (11) -
singleton
_ class (11) -
singleton
_ method (11) -
singleton
_ methods (11)
検索結果
先頭5件
-
Object
# singleton _ methods(inherited _ too = true) -> [Symbol] (6138.0) -
そのオブジェクトに対して定義されている特異メソッド名 (public あるいは protected メソッド) の一覧を返します。
...た特異メソッドとは Object#extend によって追加された特異メソッドや、
self がクラスの場合はスーパークラスのクラスメソッド(Classのインスタンスの特異メソッド)などです。
singleton_methods(false) は、Object#methods(false) と同じで......d
public; def public_self() end
end
# あるオブジェクトの特異メソッドの一覧を得る。
p obj.singleton_methods(false)
p obj.methods(false)
p Foo.singleton_methods(false)
#実行結果
[:protected_self, :public_self]
[:protected_self, :public_self]
[:protected_class_foo,......のクラスメソッドも含まれるよう true を指定したが、
# Object のクラスメソッドは一覧から排除している。
p obj.singleton_methods(true)
p Foo.singleton_methods(true) - Object.singleton_methods(true)
#実行結果
[:protected_self, :public_self, :protected_bar,... -
Object
# singleton _ class -> Class (6120.0) -
レシーバの特異クラスを返します。 まだ特異クラスがなければ、新しく作成します。
...します。
@raise TypeError レシーバが Integer、Float、Symbol の場合に発生します。
//emlist[][ruby]{
Object.new.singleton_class #=> #<Class:#<Object:0xb7ce1e24>>
String.singleton_class #=> #<Class:String>
nil.singleton_class #=> NilClass
//}
@see Object#class... -
Object
# define _ singleton _ method(symbol) { . . . } -> Symbol (6115.0) -
self に特異メソッド name を定義します。
...t[][ruby]{
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
//}... -
Object
# define _ singleton _ method(symbol , method) -> Symbol (6115.0) -
self に特異メソッド name を定義します。
...t[][ruby]{
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
//}... -
Object
# singleton _ method(name) -> Method (6114.0) -
オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。
...o.new(99)
def k.hi
"Hi, @iv = #{@iv}"
end
m = k.singleton_method(:hi) # => #<Method: #<Demo:0xf8b0c3c4 @iv=99>.hi>
m.call #=> "Hi, @iv = 99"
m = k.singleton_method(:hello) # => NameError
//}
@see Module#instance_method, Method, BasicObject#__send__, Object#send, Kernel.#eval, Object#method... -
Object
# methods(include _ inherited = true) -> [Symbol] (97.0) -
そのオブジェクトに対して呼び出せるメソッド名の一覧を返します。 このメソッドは public メソッドおよび protected メソッドの名前を返します。
...メソッドの名前を返します。
ただし特別に、引数が偽の時は Object#singleton_methods(false) と同じになっています。
@param include_inherited 引数が偽の時は Object#singleton_methods(false) と同じになります。
//emlist[例1][ruby]{
class Parent
pr......) 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.me......e)
p obj.private_methods(false)
p obj.protected_methods(false)
# 実行結果
[:protected_singleton, :public_singleton]
[:public_singleton, :public_foo]
[:private_singleton, :private_foo]
[:protected_singleton, :protected_foo]
//}
//emlist[例2][ruby]{
# あるオブジェクトの応答できる... -
Object
# initialize _ copy(obj) -> object (25.0) -
(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。
...は self を obj の内容で置き換えます。ただ
し、self のインスタンス変数や特異メソッドは変化しません。
Object#clone, Object#dupの内部で使われています。
initialize_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに......alize_copy でコピーするよう定義しておくことで、dup や clone
を再定義する必要がなくなります。
デフォルトの Object#initialize_copy は、 freeze チェックおよび型のチェックを行い self
を返すだけのメソッドです。
initialize_copy と......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
# method(name) -> Method (7.0) -
オブジェクトのメソッド name をオブジェクト化した Method オブジェクトを返します。
...ror 定義されていないメソッド名を引数として与えると発生します。
//emlist[][ruby]{
me = -365.method(:abs)
p me #=> #<Method: Integer#abs>
p me.call #=> 365
//}
@see Module#instance_method, Method, BasicObject#__send__, Object#send, Kernel.#eval, Object#singleton_method... -
Object
# private _ methods(include _ inherited = true) -> [Symbol] (7.0) -
そのオブジェクトが理解できる private メソッド名の一覧を返します。
...が理解できる private メソッド名の一覧を返します。
@param include_inherited 偽となる値を指定すると自身のクラスのスーパークラスで定義されたメソッドを除きます。
@see Module#private_instance_methods,Object#methods,Object#singleton_methods... -
Object
# protected _ methods(include _ inherited = true) -> [Symbol] (7.0) -
そのオブジェクトが理解できる protected メソッド名の一覧を返します。
...解できる protected メソッド名の一覧を返します。
@param include_inherited 偽となる値を指定すると自身のクラスのスーパークラスで定義されたメソッドを除きます。
@see Module#protected_instance_methods,Object#methods,Object#singleton_methods...