132件ヒット
[1-100件を表示]
(0.030秒)
別のキーワード
種類
- インスタンスメソッド (120)
- クラス (12)
クラス
- BasicObject (36)
- Module (36)
- Object (48)
キーワード
- Numeric (12)
-
define
_ singleton _ method (24) -
method
_ added (12) -
method
_ removed (12) -
method
_ undefined (12) -
singleton
_ method _ added (12) -
singleton
_ method _ removed (12) -
singleton
_ method _ undefined (12) -
singleton
_ methods (12)
検索結果
先頭5件
-
Object
# singleton _ method(name) -> Method (18121.0) -
オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。
...st[][ruby]{
class Demo
def initialize(n)
@iv = n
end
def hello()
"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) #... -
Object
# singleton _ methods(inherited _ too = true) -> [Symbol] (6210.0) -
そのオブジェクトに対して定義されている特異メソッド名 (public あるいは protected メソッド) の一覧を返します。
...された特異メソッドや、
self がクラスの場合はスーパークラスのクラスメソッド(Classのインスタンスの特異メソッド)などです。
singleton_methods(false) は、Object#methods(false) と同じです。
@param inherited_too 継承した特異メソッド......by]{
Parent = Class.new
class <<Parent
private; def private_class_parent() end
protected; def protected_class_parent() end
public; def public_class_parent() end
end
Foo = Class.new(Parent)
class <<Foo
private; def private_class_foo() end
protected; def protected_class_foo() end......public; def public_class_foo() end
end
module Bar
private; def private_bar() end
protected; def protected_bar() end
public; def public_bar() end
end
obj = Foo.new
class <<obj
include Bar
private; def private_self() end
protected; def protected_self() end
public;... -
Object
# define _ singleton _ method(symbol) { . . . } -> Symbol (6140.0) -
self に特異メソッド name を定義します。
...Symbol を返します。
//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.hell... -
Object
# define _ singleton _ method(symbol , method) -> Symbol (6140.0) -
self に特異メソッド name を定義します。
...Symbol を返します。
//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.hell... -
BasicObject
# singleton _ method _ removed(name) -> object (6133.0) -
特異メソッドが Module#remove_method に より削除された時にインタプリタから呼び出されます。
...][ruby]{
class Foo
def 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,Basic... -
BasicObject
# singleton _ method _ undefined(name) -> object (6133.0) -
特異メソッドが Module#undef_method または undef により未定義にされた時にインタプリタから呼び出されます。
...ソッド名が Symbol で渡されます。
//emlist[例][ruby]{
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" was undefined
//}
@see Module#method_undefined,BasicObject#singleton_method_added,BasicObject#singleton_method_removed , d:spec/def#undef... -
BasicObject
# singleton _ method _ added(name) -> object (6127.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... -
Module
# method _ added(name) -> () (14.0) -
メソッド name が追加された時にインタプリタがこのメソッドを呼び出します。
...す。
特異メソッドの追加に対するフックには
BasicObject#singleton_method_added
を使います。
@param name 追加されたメソッドの名前が Symbol で渡されます。
//emlist[例][ruby]{
class Foo
def Foo.method_added(name)
puts "method \"#{name}\" was added"... -
Module
# method _ removed(name) -> () (14.0) -
メソッドが Module#remove_method により削除 された時にインタプリタがこのメソッドを呼び出します。
...す。
特異メソッドの削除に対するフックには
BasicObject#singleton_method_removed
を使います。
@param name 削除されたメソッド名が Symbol で渡されます。
//emlist[例][ruby]{
class Foo
def Foo.method_removed(name)
puts "method \"#{name}\" was removed"...