77件ヒット
[1-77件を表示]
(0.127秒)
別のキーワード
ライブラリ
- ビルトイン (77)
クラス
- BasicObject (33)
- Object (44)
キーワード
-
define
_ singleton _ method (22) -
singleton
_ method _ added (11) -
singleton
_ method _ removed (11) -
singleton
_ method _ undefined (11) -
singleton
_ methods (11)
検索結果
先頭5件
-
Object
# singleton _ method(name) -> Method (24214.0) -
オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。
..."Hello, @iv = #{@iv}"
end
end
k = Demo.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__, Ob... -
Object
# singleton _ methods(inherited _ too = true) -> [Symbol] (12301.0) -
そのオブジェクトに対して定義されている特異メソッド名 (public あるいは protected メソッド) の一覧を返します。
...ェクトに対して定義されている特異メソッド名
(public あるいは protected メソッド) の一覧を返します。
inherited_too が真のときは継承した特異メソッドを含みます。
継承した特異メソッドとは Object#extend によって追加された特......パークラスのクラスメソッド(Classのインスタンスの特異メソッド)などです。
singleton_methods(false) は、Object#methods(false) と同じです。
@param inherited_too 継承した特異メソッドを含める場合は真を、
そうでない場......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, :pub... -
Object
# define _ singleton _ method(symbol) { . . . } -> Symbol (12221.0) -
self に特異メソッド name を定義します。
...。
//emlist[][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 t... -
Object
# define _ singleton _ method(symbol , method) -> Symbol (12221.0) -
self に特異メソッド name を定義します。
...。
//emlist[][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 t... -
BasicObject
# singleton _ method _ added(name) -> object (12220.0) -
特異メソッドが追加された時にインタプリタから呼び出されます。
...emlist[例][ruby]{
class Foo
def singleton_method_added(name)
puts "singleton method \"#{name}\" was added"
end
end
obj = Foo.new
def obj.foo
end
#=> singleton method "foo" was added
//}
@see Module#method_added,BasicObject#singleton_method_removed,BasicObject#singleton_method_undefined... -
BasicObject
# singleton _ method _ removed(name) -> object (12220.0) -
特異メソッドが Module#remove_method に より削除された時にインタプリタから呼び出されます。
...f singleton_method_removed(name)
puts "singleton method \"#{name}\" was removed"
end
end
obj = Foo.new
def obj.foo
end
class << obj
remove_method :foo
end
#=> singleton method "foo" was removed
//}
@see Module#method_removed,BasicObject#singleton_method_added,BasicObject#singleton_method... -
BasicObject
# singleton _ method _ undefined(name) -> object (12220.0) -
特異メソッドが Module#undef_method または undef により未定義にされた時にインタプリタから呼び出されます。
...{
class Foo
def singleton_method_undefined(name)
puts "singleton method \"#{name}\" was undefined"
end
end
obj = Foo.new
def obj.foo
end
def obj.bar
end
class << obj
undef_method :foo
end
obj.instance_eval {undef bar}
#=> singleton method "foo" was undefined
# singleton method "bar" w......as undefined
//}
@see Module#method_undefined,BasicObject#singleton_method_added,BasicObject#singleton_method_removed , d:spec/def#undef...