ライブラリ
- ビルトイン (456)
- erb (12)
-
minitest
/ unit (1) - mkmf (72)
- rake (12)
-
rake
/ packagetask (12) -
rexml
/ parsers / sax2parser (60) -
rexml
/ streamlistener (12) - socket (12)
- tsort (93)
クラス
- ERB (12)
- Method (24)
- Module (264)
- Object (84)
- Proc (6)
-
REXML
:: Parsers :: SAX2Parser (60) -
Rake
:: FileList (12) -
Rake
:: PackageTask (12) - Range (26)
- Refinement (4)
- Socket (12)
- TracePoint (12)
- UnboundMethod (12)
モジュール
- Enumerable (24)
- Kernel (72)
-
MiniTest
:: Assertions (1) -
REXML
:: StreamListener (12) - TSort (93)
キーワード
- < (12)
- <= (12)
- <=> (12)
- === (7)
- > (12)
- >= (12)
- ancestors (12)
-
append
_ features (12) -
assert
_ send (1) - bind (12)
-
connect
_ nonblock (12) -
const
_ defined? (12) -
const
_ get (12) -
const
_ source _ location (12) - constants (12)
- cover? (19)
-
def
_ module (12) -
defined
_ class (12) -
each
_ entry (24) -
each
_ strongly _ connected _ component (23) -
each
_ strongly _ connected _ component _ from (23) -
enable
_ config (24) - entitydecl (12)
- extend (12)
-
import
_ methods (4) - include? (12)
- included (12)
-
included
_ modules (12) - inspect (12)
-
is
_ a? (12) -
kind
_ of? (12) - listen (60)
-
method
_ defined? (12) - methods (12)
-
package
_ files (12) -
prepend
_ features (12) -
private
_ instance _ methods (12) -
private
_ method _ defined? (12) -
protected
_ method _ defined? (12) -
public
_ method _ defined? (12) - resolve (12)
-
respond
_ to? (12) -
respond
_ to _ missing? (12) -
ruby2
_ keywords (18) -
singleton
_ methods (12) -
strongly
_ connected _ components (12) -
to
_ s (12) -
try
_ cpp (24) - tsort (12)
-
tsort
_ each (23) -
with
_ config (24)
検索結果
先頭5件
-
Module
# include(*mod) -> self (18210.0) -
モジュール mod をインクルードします。
...てしまうような include を行った場合に発生します。
//emlist[例][ruby]{
module M
end
module M2
include M
end
module M
include M2
end
//}
実行結果:
-:3:in `append_features': cyclic include detected (ArgumentError)
from -:3:in `include'
from -:3......インクルードは多重継承の代わりに用いられており、 mix-in とも呼びます。
//emlist[例][ruby]{
class C
include FileTest
include Math
end
p C.ancestors
# => [C, Math, FileTest, Object, Kernel]
//}
モジュールの機能追加は、クラスの継承関係の間......の順序です)。
同じモジュールを二回以上 include すると二回目以降は無視されます。
//emlist[例][ruby]{
module M
end
class C1
include M
end
class C2 < C1
include M # この include は無視される
end
p C2.ancestors # => [C2, C1, M, Object, Kernel]
//}... -
Object
# extend(*modules) -> self (6167.0) -
引数で指定したモジュールのインスタンスメソッドを self の特異 メソッドとして追加します。
...ールのインスタンスメソッドを self の特異
メソッドとして追加します。
Module#include は、クラス(のインスタンス)に機能を追加します
が、extend は、ある特定のオブジェクトだけにモジュールの機能を追加
したいときに使用......ule Foo
def a
'ok Foo'
end
end
module Bar
def b
'ok Bar'
end
end
obj = Object.new
obj.extend Foo, Bar
p obj.a #=> "ok Foo"
p obj.b #=> "ok Bar"
class Klass
include Foo
extend Bar
end
p Klass.new.a #=> "ok Foo"
p Klass.b #=> "ok Bar"
//}
extend の機能は、「特異ク......ただしその場合、フック用のメソッド
が Module#extended ではなく Module#included になるという違いがあります。
//emlist[][ruby]{
# obj.extend Foo, Bar とほぼ同じ
class << obj
include Foo, Bar
end
//}
@see Module#extend_object,Module#include,Module#extended... -
Module
# included(class _ or _ module) -> () (6159.0) -
self が Module#include されたときに対象のクラスまたはモジュー ルを引数にしてインタプリタがこのメソッドを呼び出します。
...f が Module#include されたときに対象のクラスまたはモジュー
ルを引数にしてインタプリタがこのメソッドを呼び出します。
@param class_or_module Module#include を実行したオブジェクト
//emlist[例][ruby]{
module Foo
def self.included(mod)
p......"#{mod} include #{self}"
end
end
class Bar
include Foo
end
# => "Bar include Foo"
//}
@see Module#append_features... -
Module
# prepend _ features(mod) -> self (6143.0) -
Module#prepend から呼び出されるメソッドで、 prepend の処理の実体です。このメソッド自体は mod で指定した モジュール/クラスの継承チェインの先頭に self を追加します。
...Module#prepend から呼び出されるメソッドで、
prepend の処理の実体です。このメソッド自体は mod で指定した
モジュール/クラスの継承チェインの先頭に self を追加します。
このメソッドを上書きすることで、prepend の処理を変......m mod prepend を呼び出したモジュール
@return mod が返されます
//emlist[例][ruby]{
class Recorder
RECORDS = []
end
module X
def self.prepend_features(mod)
Recorder::RECORDS << mod
end
end
class A
prepend X
end
class B
include X
end
class C
prepend X
end
Recorde......r::RECORDS # => [A, C]
//}
@see Module#prepend, Module#prepended... -
Module
# include?(mod) -> bool (6138.0) -
self かその親クラス / 親モジュールがモジュール mod を インクルードしていれば true を返します。
...クラス / 親モジュールがモジュール mod を
インクルードしていれば true を返します。
@param mod Module を指定します。
//emlist[例][ruby]{
module M
end
class C1
include M
end
class C2 < C1
end
p C1.include?(M) # => true
p C2.include?(M) # => true
//}... -
Module
# append _ features(module _ or _ class) -> self (6131.0) -
モジュール(あるいはクラス)に self の機能を追加します。
...は Module#include の実体であり、
include を Ruby で書くと以下のように定義できます。
//emlist[例][ruby]{
def include(*modules)
modules.reverse_each do |mod|
# append_features や included はプライベートメソッドなので
# 直接 mod.append_features(sel......f) などとは書けない
mod.__send__(:append_features, self)
mod.__send__(:included, self)
end
end
//}
@see Module#included... -
Module
# included _ modules -> [Module] (6119.0) -
self にインクルードされているモジュールの配列を返します。
...self にインクルードされているモジュールの配列を返します。
//emlist[例][ruby]{
module Mixin
end
module Outer
include Mixin
end
Mixin.included_modules #=> []
Outer.included_modules #=> [Mixin]
//}
@see Module#ancestors... -
MiniTest
:: Assertions # assert _ send(array , message = nil) -> true (6107.0) -
引数から、式を取り出して評価した結果が真の場合、検査にパスしたことになります。
...します。
文字列か Proc を指定します。Proc である場合は Proc#call した
結果を使用します。
@raise MiniTest::Assertion 取り出した式が偽を返す場合に発生します。
例:
assert_send([%w[foo bar baz], :include?, 'baz'])... -
Object
# respond _ to?(name , include _ all = false) -> bool (192.0) -
オブジェクトがメソッド name を持つとき真を返します。
...o_missing? を呼
び出してその結果を返します。
@param name Symbol または文字列で指定するメソッド名です。
@param include_all private メソッドと protected メソッドを確認の対象に
含めるかを true か false で指定します。......は false(含めない) を指定した事になります。
//emlist[][ruby]{
class F
def hello
"Bonjour"
end
end
class D
private
def hello
"Guten Tag"
end
end
list = [F.new,D.new]
list.each{|it| puts it.hello if it.respond_to?(:hello)}
#=> Bonjour
list.each{|it| it.instan......ish
end
def start
puts "start"
end
def template_method
raise NotImplementedError.new
end
def finish
puts "finish"
end
end
class ImplTemplateMethod
include Template
def template_method
"implement template_method"
end
end
class NotImplTemplateMethod
include T... -
Object
# methods(include _ inherited = true) -> [Symbol] (180.0) -
そのオブジェクトに対して呼び出せるメソッド名の一覧を返します。 このメソッドは public メソッドおよび protected メソッドの名前を返します。
...ます。
@param include_inherited 引数が偽の時は Object#singleton_methods(false) と同じになります。
//emlist[例1][ruby]{
class Parent
private; def private_parent() end
protected; def protected_parent() end
public; def public_parent() end
end
class Foo < Parent......vate; def private_foo() end
protected; def protected_foo() end
public; def public_foo() end
end
obj = Foo.new
class <<obj
private; def private_singleton() end
protected; def protected_singleton() end
public; def public_singleton() end
end
# あるオブジェク...