るりまサーチ

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

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

検索結果

<< 1 2 3 ... > >>

Module#prepend(*modules) -> self (6158.0)

指定したモジュールを self の継承チェインの先頭に「追加する」ことで self の定数、メソッド、モジュール変数を「上書き」します。

...たメソッドは
override されます。

module
s で指定したモジュールは後ろから順に処理されるため、
module
s の先頭が最も優先されます。

また、継承によってこの「上書き」を処理するため、prependの引数として
渡したモジュール...
...理は modules の各要素の prepend_features を後ろから順に呼びだすだけです。
Module
#prepend_features が継承チェインの改変を実行し、結果として上のような
処理が実現されます。そのため、prepend_features を override することで
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" # (3x)
end

end


class A
prepend X

def foo...

Module#ruby2_keywords(method_name, ...) -> nil (6147.0)

For the given method names, marks the method as passing keywords through a normal argument splat. This should only be called on methods that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the method such that if the method is called with keyword arguments, the final hash argument is marked with a special flag such that if it is the final element of a normal argument splat to another method call, and that method call does not include explicit keywords or a keyword splat, the final element is interpreted as keywords. In other words, keywords will be passed through the method to other methods.

...r
method, and only for backwards compatibility with Ruby versions before
2.7.

This method will probably be removed at some point, as it exists only
for backwards compatibility. As it does not exist in Ruby versions
before 2.7, check that the module responds to this method before calling
it. Also, b...
...aware that if this method is removed, the behavior of the
method will change so that it does not pass through keywords.

//emlist[例][ruby]{
module
Mod
def foo(meth, *args, &block)
send(:"do_#{meth}", *args, &block)
end

ruby
2_keywords(:foo) if respond_to?(:ruby2_keywords, true)
end

//}...

Module#prepend_features(mod) -> self (6146.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#append_features(module_or_class) -> self (6128.0)

モジュール(あるいはクラス)に self の機能を追加します。

...ドは Module#include の実体であり、
include を Ruby で書くと以下のように定義できます。

//emlist[例][ruby]{
def include(*modules)
module
s.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#extend_object(obj) -> object (6128.0)

Object#extend の実体です。オブジェクトにモジュールの機能を追加します。

...Object#extend の実体です。オブジェクトにモジュールの機能を追加します。

Object#extend は、Ruby で書くと以下のように定義できます。

//emlist[例][ruby]{
def extend(*modules)
module
s.reverse_each do |mod|
# extend_object や extended はプライ...
...ベートメソッドなので
# 直接 mod.extend_object(self) などとは書けない
mod.__send__(:extend_object, self)
mod.__send__(:extended, self)
end

end

//}

extend_object のデフォルトの実装では、self に定義されて
いるインスタンスメソッドを obj...
...の特異メソッドとして追加します。

@param obj self の機能を追加するオブジェクトを指定します。

@return obj で指定されたオブジェクトを返します。

@see Module#extended...

絞り込み条件を変える

Module#prepended(class_or_module) -> () (6128.0)

self が Module#prepend されたときに対象のクラスまたはモジュールを 引数にしてインタプリタがこのメソッドを呼び出します。

...self が Module#prepend されたときに対象のクラスまたはモジュールを
引数にしてインタプリタがこのメソッドを呼び出します。

@param class_or_module Module#prepend を実行したオブジェクト

//emlist[例][ruby]{
module
A
def self.prepended(mod)...
...puts "#{self} prepended to #{mod}"
end

end

module
Enumerable
prepend A
end

# => "A prepended to Enumerable"
//}

@see Module#included, Module#prepend, Module#prepend_features...

Module#extended(obj) -> () (6122.0)

self が他のオブジェクト に Object#extend されたときに 呼ばれます。引数には extend を行ったオブジェクトが渡されます。

...ect#extend されたときに
呼ばれます。引数には extend を行ったオブジェクトが渡されます。

@param obj Object#extend を行ったオブジェクト

//emlist[例][ruby]{
module
Foo
def self.extended(obj)
p "#{obj} extend #{self}"
end

end


Object.new.extend Foo

#...
...=> "#<Object:0x401cbc3c> extend Foo"
//}

@see Module#extend_object...

Module#autoload(const_name, feature) -> nil (88.0)

定数 const_name を最初に参照した時に feature を Kernel.#require するように設定します。

...ruby]{
# ------- /tmp/foo.rb ---------
class Foo
class Bar
end

end

# ----- end of /tmp/foo.rb ----

class Foo
autoload :Bar, '/tmp/foo'
end

p Foo::Bar #=> Foo::Bar
//}

以下のようにモジュールを明示的にレシーバとして呼び出すこともできます。

//emlist[例][ruby...
...Foo
class Bar
end

end

# ----- end of /tmp/foo.rb ----

class Foo
end

Foo.autoload :Bar, '/tmp/foo'
p Foo::Bar #=> Foo::Bar
//}

以下のように、autoload したライブラリがネストした定数を定義しない場
合、NameError が発生します。

//emlist[例][ruby]{
# ------- /...
...tmp/bar.rb ---------
class Bar
end

# ----- end of /tmp/bar.rb ----

class Foo
autoload :Bar, '/tmp/bar.rb'
end

p Foo::Bar
#=> -:4:in `<main>': uninitialized constant Foo::Bar (NameError)
//}

@see Kernel.#autoload...

Module#undef_method(*name) -> self (88.0)

このモジュールのインスタンスメソッド name を未定義にします。

...//emlist[例][ruby]{
class A
def ok
puts 'A'
end

end

class B < A
def ok
puts 'B'
end

end


B.new.ok # => B

# undef_method の場合はスーパークラスに同名のメソッドがあっても
# その呼び出しはエラーになる
class B
undef_method :ok
end

B.new.ok #...
...class B
remove_method :ok
end

B.new.ok # => A
//}

また、undef 文と undef_method の違いは、
メソッド名を String または Symbol で与えられることです。

//emlist[例][ruby]{
module
M1
def foo
end

def self.moo
undef foo
end

end

M1.instance_methods false #=>...
...["foo"]
M1.moo
M1.instance_methods false #=> []
module
M2
def foo
end

def self.moo
undef_method :foo
end

end

M2.instance_methods false #=> ["foo"]
M2.moo
M2.instance_methods false #=> []
//}...
<< 1 2 3 ... > >>