るりまサーチ

最速Rubyリファレンスマニュアル検索!
299件ヒット [1-100件を表示] (0.045秒)
トップページ > クエリ:end[x] > クエリ:Singleton[x]

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. range end

検索結果

<< 1 2 3 > >>

Singleton (38052.0)

Singleton パターンを提供するモジュールです。

...Singleton パターンを提供するモジュールです。

Mix-in により singleton パターンを提供します。

Singleton
モジュールを include することにより、クラスは
高々ひとつのインスタンスしか持たないことが保証されます。

Singleton
を M...
...ire 'singleton'

class SomeSingletonClass
include Singleton
#....
end


a = SomeSingletonClass.instance
b = SomeSingletonClass.instance # a and b are same object
p [a,b] # => [#<SomeSingletonClass:0x0000562e6e18ddd0>, #<SomeSingletonClass:0x0000562e6e18ddd0>]
a = SomeSingletonClass...
....new # => NoMethodError (private method `new' called for SomeSingletonClass:Class)...

Object#singleton_methods(inherited_too = true) -> [Symbol] (6233.0)

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

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

singleton
_methods(false) は、Object#methods(false) と...
...vate_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
pri...
...vate; 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; def public_self() end
end


# あるオブジェクトの...

BasicObject#singleton_method_undefined(name) -> object (6167.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" wa...
...s undefined
//}

@see Module#method_undefined,BasicObject#singleton_method_added,BasicObject#singleton_method_removed , d:spec/def#undef...

BasicObject#singleton_method_removed(name) -> object (6155.0)

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

...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,BasicObject#singleton_met...

BasicObject#singleton_method_added(name) -> object (6149.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...

絞り込み条件を変える

Object#define_singleton_method(symbol) { ... } -> Symbol (6138.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 (6138.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#singleton_method(name) -> Method (6137.0)

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

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

Module#singleton_class? -> bool (6125.0)

self が特異クラスの場合に true を返します。そうでなければ false を返し ます。

...self が特異クラスの場合に true を返します。そうでなければ false を返し
ます。

//emlist[例][ruby]{
class C
end

C.singleton_class? # => false
C.singleton_class.singleton_class? # => true
//}...
<< 1 2 3 > >>