ライブラリ
- ビルトイン (1597)
- erb (12)
-
fiddle
/ import (84) -
irb
/ context (12) -
minitest
/ spec (1) -
minitest
/ unit (1) - psych (8)
- rake (12)
-
rdoc
/ code _ object (12) -
rdoc
/ context (108) -
rdoc
/ stats (24) -
rdoc
/ top _ level (36) - win32ole (24)
クラス
- BasicObject (72)
- ERB (12)
-
Enumerator
:: Lazy (48) -
IRB
:: Context (12) - Method (36)
- Module (1116)
- Object (240)
- Proc (18)
-
RDoc
:: CodeObject (12) -
RDoc
:: Context (108) -
RDoc
:: Stats (24) -
RDoc
:: TopLevel (36) - Refinement (4)
- TracePoint (12)
- UnboundMethod (24)
-
WIN32OLE
_ TYPE (24)
モジュール
- Enumerable (48)
-
Fiddle
:: Importer (84) -
MiniTest
:: Assertions (1)
キーワード
- < (12)
- <= (12)
- <=> (12)
- === (24)
- > (12)
- >= (12)
-
add
_ class _ or _ module (24) -
add
_ module (12) -
alias
_ method (12) - ancestors (12)
-
append
_ features (12) -
assert
_ instance _ of (1) - attr (36)
-
attr
_ accessor (12) -
attr
_ reader (12) -
attr
_ writer (12) - autoload (12)
- autoload? (12)
- bind (24)
- class (12)
-
class
_ eval (24) -
class
_ exec (12) -
class
_ variable _ defined? (12) -
class
_ variable _ get (12) -
class
_ variable _ set (12) -
class
_ variables (12) -
const
_ added (3) -
const
_ defined? (12) -
const
_ get (12) -
const
_ missing (12) -
const
_ set (12) -
const
_ source _ location (12) - constants (12)
-
create
_ value (12) -
def
_ module (12) -
default
_ event _ sources (12) -
define
_ method (24) -
defined
_ class (12) -
deprecate
_ constant (12) -
each
_ classmodule (12) -
enum
_ for (48) - extend (12)
-
extend
_ object (12) - extended (12)
- extern (12)
-
find
_ enclosing _ module _ named (12) -
find
_ local _ symbol (24) -
find
_ module _ named (24) -
find
_ symbol (12) - freeze (12)
-
import
_ methods (4) - include (12)
- include? (12)
- included (12)
-
included
_ modules (12) -
infect
_ with _ assertions (1) -
initialize
_ classes _ and _ modules (12) - inspect (24)
-
instance
_ eval (24) -
instance
_ exec (12) -
instance
_ method (12) -
instance
_ methods (12) -
instance
_ variables (12) -
is
_ a? (12) -
kind
_ of? (12) - lambda? (12)
-
load
_ modules (12) -
max
_ by (48) - method (12)
-
method
_ added (12) -
method
_ defined? (12) -
method
_ removed (12) -
method
_ undefined (12) - methods (12)
-
module
_ eval (24) -
module
_ exec (12) -
module
_ function (36) - modules (12)
- name (12)
-
num
_ modules (12) -
num
_ modules= (12) -
ole
_ type (12) - owner (24)
- prepend (12)
-
prepend
_ features (12) - prepended (12)
- private (48)
-
private
_ class _ method (24) -
private
_ constant (12) -
private
_ instance _ methods (12) -
private
_ method _ defined? (12) -
private
_ methods (12) - protected (48)
-
protected
_ instance _ methods (12) -
protected
_ method _ defined? (12) -
protected
_ methods (12) -
psych
_ yaml _ as (4) - public (48)
-
public
_ class _ method (24) -
public
_ constant (12) -
public
_ instance _ method (12) -
public
_ instance _ methods (12) -
public
_ method (12) -
public
_ method _ defined? (12) -
public
_ methods (12) -
rake
_ extension (12) - refine (12)
-
remove
_ class _ variable (12) -
remove
_ classes _ and _ modules (12) -
remove
_ const (12) -
remove
_ instance _ variable (12) -
remove
_ method (12) -
respond
_ to? (12) -
ruby2
_ keywords (18) -
singleton
_ class? (12) -
singleton
_ method (12) -
singleton
_ method _ added (12) -
singleton
_ method _ removed (12) -
singleton
_ method _ undefined (12) -
singleton
_ methods (12) - sizeof (12)
- struct (12)
-
to
_ enum (48) -
to
_ s (24) -
undef
_ method (12) - union (12)
- using (12)
- value (12)
-
yaml
_ as (4)
検索結果
先頭5件
-
Module
# included(class _ or _ module) -> () (21142.0) -
self が Module#include されたときに対象のクラスまたはモジュー ルを引数にしてインタプリタがこのメソッドを呼び出します。
...self が 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(*modules) -> self (21137.0) -
指定したモジュールを self の継承チェインの先頭に「追加する」ことで self の定数、メソッド、モジュール変数を「上書き」します。
...追加されるため、結果として self で定義されたメソッドは
override されます。
modules で指定したモジュールは後ろから順に処理されるため、
modules の先頭が最も優先されます。
また、継承によってこの「上書き」を処理す......のモジュール/クラスのメソッドを呼び出すことができます。
実際の処理は modules の各要素の prepend_features を後ろから順に呼びだすだけです。
Module#prepend_features が継承チェインの改変を実行し、結果として上のような
処理......とで
prepend の処理を追加/変更できます。
@param modules prepend する Module を指定します
@see Module#prepend_features, Module#prepended
//emlist[例][ruby]{
# super と prepend の組み合わせの例
module X
def foo
puts "X1" # (1x)
super # (2x)
puts "X2" #... -
Module
# refine(klass) { . . . } -> Module (21130.0) -
引数 klass で指定したクラスまたはモジュールだけに対して、ブロックで指定した機能を提供で きるモジュールを定義します。定義した機能は Module#refine を使用せずに直 接 klass に対して変更を行う場合と異なり、限られた範囲のみ有効にできます。 そのため、既存の機能を局所的に修正したい場合などに用いる事ができます。
...モジュールだけに対して、ブロックで指定した機能を提供で
きるモジュールを定義します。定義した機能は Module#refine を使用せずに直
接 klass に対して変更を行う場合と異なり、限られた範囲のみ有効にできます。
そのた......ticles/0041/0041-200Special-refinement.html
* https://docs.ruby-lang.org/en/master/syntax/refinements_rdoc.html
定義した機能は main.using, Module#using を実行した場合のみ
有効になります。
@param klass 拡張する対象のクラスまたはモジュールを指定します......ックで指定した機能を持つ無名のモジュールを返します。
//emlist[例][ruby]{
class C
def foo
puts "C#foo"
end
end
module M
refine C do
def foo
puts "C#foo in M"
end
end
end
x = C.new
x.foo # => "C#foo"
using M
x = C.new
x.foo # => "C#foo in M"
//... -
Module
# ancestors -> [Class , Module] (21114.0) -
クラス、モジュールのスーパークラスとインクルードしているモジュール を優先順位順に配列に格納して返します。
...先順位順に配列に格納して返します。
//emlist[例][ruby]{
module Foo
end
class Bar
include Foo
end
class Baz < Bar
p ancestors
p included_modules
p superclass
end
# => [Baz, Bar, Foo, Object, Kernel, BasicObject]
# => [Foo, Kernel]
# => Bar
//}
@see Module#included_modules... -
Module
# append _ features(module _ or _ class) -> self (21114.0) -
モジュール(あるいはクラス)に self の機能を追加します。
...ラス)に self の機能を追加します。
このメソッドは Module#include の実体であり、
include を Ruby で書くと以下のように定義できます。
//emlist[例][ruby]{
def include(*modules)
modules.reverse_each do |mod|
# append_features や included はプライ......ベートメソッドなので
# 直接 mod.append_features(self) などとは書けない
mod.__send__(:append_features, self)
mod.__send__(:included, self)
end
end
//}
@see Module#included... -
Module
# using(module) -> self (21114.0) -
引数で指定したモジュールで定義された拡張を現在のクラス、モジュールで有 効にします。
...ルで有
効にします。
有効にした拡張の有効範囲については以下を参照してください。
* https://docs.ruby-lang.org/en/master/syntax/refinements_rdoc.html#label-Scope
@param module 有効にするモジュールを指定します。
@see Module#refine, main.using... -
Module
# constants(inherit = true) -> [Symbol] (21049.0) -
そのモジュール(またはクラス)で定義されている定数名の配列を返します。
...@see Module.constants, Kernel.#local_variables, Kernel.#global_variables, Object#instance_variables, Module#class_variables
//emlist[Module.constants と Module#constants の違い][ruby]{
# 出力の簡略化のため起動時の定数一覧を取得して後で差し引く
$clist = Module.const......ない
p Module.constants - $clist # => [:BAR, :Bar, :Foo]
class Baz
# Baz は定数を含まない
p constants # => []
# ネストしたクラスでは、外側のクラスで定義した定数は
# 参照可能なので、BAR は、Module.constant......s には含まれる
# (クラス Baz も Bar の定数なので同様)
p Module.constants - $clist # => [:BAR, :Baz, :Foo, :Bar]
end
end
//}... -
Module
# include(*mod) -> self (21037.0) -
モジュール mod をインクルードします。
...ます。
@param mod Module のインスタンス( Enumerable など)を指定します。
@raise ArgumentError 継承関係が循環してしまうような include を行った場合に発生します。
//emlist[例][ruby]{
module M
end
module M2
include M
end
module M
include M2
end
//}......ールのほうが
先に行われます
(上の例の Module#ancestors の結果がメソッド探索の順序です)。
同じモジュールを二回以上 include すると二回目以降は無視されます。
//emlist[例][ruby]{
module M
end
class C1
include M
end
class C2 < C1
include... -
Module
# prepend _ features(mod) -> self (21035.0) -
Module#prepend から呼び出されるメソッドで、 prepend の処理の実体です。このメソッド自体は mod で指定した モジュール/クラスの継承チェインの先頭に self を追加します。
...Module#prepend から呼び出されるメソッドで、
prepend の処理の実体です。このメソッド自体は mod で指定した
モジュール/クラスの継承チェインの先頭に self を追加します。
このメソッドを上書きすることで、prepend の処理を変......れます
//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
Recorder::RECORDS # => [A, C]
//}
@see Module#prepend, Module#prepended...