ライブラリ
- ビルトイン (180)
- forwardable (44)
- profiler (6)
-
rdoc
/ context (11) - singleton (44)
クラス
- BasicObject (33)
- Module (37)
- Object (110)
-
RDoc
:: Context (11)
モジュール
- SingleForwardable (44)
- Singleton (33)
キーワード
-
Profiler
_ _ (6) - Ruby用語集 (11)
- clone (11)
-
def
_ delegator (11) -
def
_ delegators (11) -
def
_ single _ delegator (11) -
def
_ single _ delegators (11) -
define
_ singleton _ method (22) - dup (11)
-
initialize
_ copy (11) - instance (11)
-
irb
/ completion (11) -
method
_ undefined (11) - methods (11)
-
private
_ class _ method (15) -
private
_ methods (11) -
protected
_ methods (11) -
public
_ methods (11) -
rb
_ define _ singleton _ method (11) -
rb
_ obj _ singleton _ methods (11) -
rb
_ singleton _ class (11) -
rb
_ singleton _ class _ attached (11) -
rb
_ singleton _ class _ clone (11) -
rb
_ singleton _ class _ new (11) -
set
_ visibility _ for (11) - singleton (11)
-
singleton
_ class (11) -
singleton
_ class? (11) -
singleton
_ method (11) -
singleton
_ method _ added (11) -
singleton
_ method _ removed (11) -
singleton
_ method _ undefined (11) -
singleton
_ methods (11)
検索結果
-
Singleton (50046.0)
-
Singleton パターンを提供するモジュールです。
...Singleton パターンを提供するモジュールです。
Mix-in により singleton パターンを提供します。
Singleton モジュールを include することにより、クラスは
高々ひとつのインスタンスしか持たないことが保証されます。
Singleton を M......ix-in したクラスの
クラスメソッド instance はその唯一のインスタンスを返します。
new は private メソッドに移され、外部から呼び出そうとするとエラーになります。
=== サンプルコード
require 'singleton'
class SomeSingletonClass......lude 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' call... -
Singleton
. instance -> object (33112.0) -
そのクラスの唯一のインスタンスを返します。 最初に呼ばれたときはそのインスタンスを生成します。
...そのクラスの唯一のインスタンスを返します。
最初に呼ばれたときはそのインスタンスを生成します。
Singleton を include したクラスで定義されますので、
正確には Singleton モジュールのメソッドではありません。... -
irb
/ completion (32006.0) -
irb の completion 機能を提供するライブラリです。
...irb の completion 機能を提供するライブラリです。
=== 使い方
$ irb -r irb/completion
とするか, ~/.irbrc 中に
require "irb/completion"
を入れてください.
irb実行中に require "irb/completion" してもよいです.
irb 実行中に [Tab] を押すとコ......全に補完します.
irb(main):001:0> in
in inspect instance_eval
include install_alias_method instance_of?
initialize install_aliases instance_variables
irb(main):001:0> inspect
"main"
irb(main):002:0> foo = Objec......lic_methods
foo.=~ foo.id foo.respond_to?
foo.__id__ foo.inspect foo.send
foo.__send__ foo.instance_eval foo.singleton_methods
foo.class foo.instance_of? foo.taint
foo.clone foo.i... -
Singleton
# clone (30100.0) -
@raise TypeError このメソッドを呼び出した場合に発生します。
...@raise TypeError このメソッドを呼び出した場合に発生します。... -
Singleton
# dup (27000.0) -
@raise TypeError このメソッドを呼び出した場合に発生します。
...@raise TypeError このメソッドを呼び出した場合に発生します。... -
Object
# define _ singleton _ method(symbol) { . . . } -> Symbol (24438.0) -
self に特異メソッド name を定義します。
...self に特異メソッド name を定義します。
@param symbol メソッド名を String または Symbol で指定します。
@param method Proc、Method あるいは UnboundMethod の
いずれかのインスタンスを指定します。
@return メソッド名を表す Sy......mbol を返します。
//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 there!"
//}... -
Object
# define _ singleton _ method(symbol , method) -> Symbol (24438.0) -
self に特異メソッド name を定義します。
...self に特異メソッド name を定義します。
@param symbol メソッド名を String または Symbol で指定します。
@param method Proc、Method あるいは UnboundMethod の
いずれかのインスタンスを指定します。
@return メソッド名を表す Sy......mbol を返します。
//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 there!"
//}... -
void rb
_ define _ singleton _ method(VALUE obj , const char *name , VALUE (*func)() , int argc) (24300.0) -
obj に特異メソッド name を定義します。 メソッドの実体を func に関数ポインタで与え、その関数がとる 引数のタイプを argc に渡します。argc のフォーマットに ついては rb_define_method の記述を参照してください。
...obj に特異メソッド name を定義します。
メソッドの実体を func に関数ポインタで与え、その関数がとる
引数のタイプを argc に渡します。argc のフォーマットに
ついては rb_define_method の記述を参照してください。... -
BasicObject
# singleton _ method _ undefined(name) -> object (21437.0) -
特異メソッドが Module#undef_method または undef により未定義にされた時にインタプリタから呼び出されます。
...が Module#undef_method または
undef により未定義にされた時にインタプリタから呼び出されます。
通常のメソッドの未定義に対するフックには
Module#method_undefined を使います。
@param name 未定義にされたメソッド名が Symbol で渡さ......list[例][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... -
Module
# singleton _ class? -> bool (21319.0) -
self が特異クラスの場合に true を返します。そうでなければ false を返し ます。
...self が特異クラスの場合に true を返します。そうでなければ false を返し
ます。
//emlist[例][ruby]{
class C
end
C.singleton_class? # => false
C.singleton_class.singleton_class? # => true
//}...