るりまサーチ

最速Rubyリファレンスマニュアル検索!
132件ヒット [1-100件を表示] (0.076秒)
トップページ > クエリ:C[x] > クエリ:singleton_method[x] > 種類:インスタンスメソッド[x]

別のキーワード

  1. singleton clone
  2. singleton dup
  3. singleton instance
  4. object define_singleton_method
  5. _builtin define_singleton_method

検索結果

<< 1 2 > >>

Object#singleton_method(name) -> Method (21160.0)

オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。

...st[][ruby]{
c
lass 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) #...
...=> NameError
//}

@see Module#instance_method, Method, BasicObject#__send__, Object#send, Kernel.#eval, Object#method...

BasicObject#singleton_method_added(name) -> object (9226.0)

特異メソッドが追加された時にインタプリタから呼び出されます。

...emlist[例][ruby]{
c
lass 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 (9226.0)

特異メソッドが Module#remove_method に より削除された時にインタプリタから呼び出されます。

...]{
c
lass Foo
def singleton_method_removed(name)
puts "singleton method \"#{name}\" was removed"
end
end

obj = Foo.new
def obj.foo
end

c
lass << obj
remove_method :foo
end

#=> singleton method "foo" was removed
//}

@see Module#method_removed,BasicObject#singleton_method_added,BasicObject...

BasicObject#singleton_method_undefined(name) -> object (9226.0)

特異メソッドが Module#undef_method または undef により未定義にされた時にインタプリタから呼び出されます。

...l で渡されます。

//emlist[例][ruby]{
c
lass 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

c
lass << 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...

Object#define_singleton_method(symbol) { ... } -> Symbol (9151.0)

self に特異メソッド name を定義します。

...hod Proc、Method あるいは UnboundMethod の
いずれかのインスタンスを指定します。

@return メソッド名を表す Symbol を返します。

//emlist[][ruby]{
c
lass A
c
lass << 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 (9151.0)

self に特異メソッド name を定義します。

...hod Proc、Method あるいは UnboundMethod の
いずれかのインスタンスを指定します。

@return メソッド名を表す Symbol を返します。

//emlist[][ruby]{
c
lass A
c
lass << 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_methods(inherited_too = true) -> [Symbol] (9107.0)

そのオブジェクトに対して定義されている特異メソッド名 (public あるいは protected メソッド) の一覧を返します。

...して定義されている特異メソッド名
(public あるいは protected メソッド) の一覧を返します。

inherited_too が真のときは継承した特異メソッドを含みます。
継承した特異メソッドとは Object#extend によって追加された特異メソッド...
...や、
self がクラスの場合はスーパークラスのクラスメソッド(Classのインスタンスの特異メソッド)などです。

singleton_method
s(false) は、Object#methods(false) と同じです。

@param inherited_too 継承した特異メソッドを含める場合は真を...
...t = Class.new

c
lass <<Parent
private; def private_class_parent() end
protected; def protected_class_parent() end
public; def public_class_parent() end
end

Foo = Class.new(Parent)

c
lass <<Foo
private; def private_class_foo() end
protected; def protected_class_foo() end
public;...

Object#method(name) -> Method (3041.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...

Module#method_undefined(name) -> () (43.0)

このモジュールのインスタンスメソッド name が Module#undef_method によって削除されるか、 undef 文により未定義にされると、インタプリタがこのメソッドを呼び出します。

...の削除をフックするには
BasicObject#singleton_method_undefined
を使います。

@param name 削除/未定義にされたメソッド名が Symbol で渡されます。

//emlist[例][ruby]{
c
lass C
def C.method_undefined(name)
puts "method C\##{name} was undefined"
end

def fo...
...o
end
def bar
end

undef_method :foo
undef bar
end
//}

実行結果:

method C#foo was undefined
method C#bar was undefined...
<< 1 2 > >>