るりまサーチ

最速Rubyリファレンスマニュアル検索!
1091件ヒット [1-100件を表示] (0.028秒)
トップページ > クエリ:ruby[x] > クラス:Module[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#ruby2_keywords(method_name, ...) -> nil (6132.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#const_missing(name) (23.0)

定義されていない定数を参照したときに Ruby インタプリタが このメソッドを呼びます。

...い定数を参照したときに Ruby インタプリタが
このメソッドを呼びます。

@param name 参照した定数名の Symbol

@raise NameError このメソッドを呼び出した場合、デフォルトで発生する例外


//emlist[例][ruby]{
class Foo
def Foo.const_missing(...

Module#attr(*name) -> [Symbol] (19.0)

インスタンス変数読み取りのためのインスタンスメソッド name を定義します。

...ます。

//emlist[例][ruby]{
class User
attr :name # => [:name]
# 複数の名前を渡すこともできる
attr :id, :age # => [:id, :age]
end
//}

このメソッドで定義されるアクセスメソッドの定義は次の通りです。

//emlist[例][ruby]{
def name
@name
end
//}...
...た場合には、属性の書き込み用メソッド name= も同時に定義されます。
その定義は次の通りです。

//emlist[例][ruby]{
def name=(val)
@name = val
end
//}

第 2 引数 に true か false を指定する方法は非推奨です。

@param name String または Sym...

Module#attr(name, false) -> [Symbol] (19.0)

インスタンス変数読み取りのためのインスタンスメソッド name を定義します。

...ます。

//emlist[例][ruby]{
class User
attr :name # => [:name]
# 複数の名前を渡すこともできる
attr :id, :age # => [:id, :age]
end
//}

このメソッドで定義されるアクセスメソッドの定義は次の通りです。

//emlist[例][ruby]{
def name
@name
end
//}...
...た場合には、属性の書き込み用メソッド name= も同時に定義されます。
その定義は次の通りです。

//emlist[例][ruby]{
def name=(val)
@name = val
end
//}

第 2 引数 に true か false を指定する方法は非推奨です。

@param name String または Sym...

Module#attr(name, true) -> [Symbol] (19.0)

インスタンス変数読み取りのためのインスタンスメソッド name を定義します。

...ます。

//emlist[例][ruby]{
class User
attr :name # => [:name]
# 複数の名前を渡すこともできる
attr :id, :age # => [:id, :age]
end
//}

このメソッドで定義されるアクセスメソッドの定義は次の通りです。

//emlist[例][ruby]{
def name
@name
end
//}...
...た場合には、属性の書き込み用メソッド name= も同時に定義されます。
その定義は次の通りです。

//emlist[例][ruby]{
def name=(val)
@name = val
end
//}

第 2 引数 に true か false を指定する方法は非推奨です。

@param name String または Sym...

絞り込み条件を変える

Module#autoload(const_name, feature) -> nil (19.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...
...下のように、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...

Module#include(*mod) -> self (19.0)

モジュール mod をインクルードします。

...ます。

@param mod Module のインスタンス( Enumerable など)を指定します。

@raise ArgumentError 継承関係が循環してしまうような include を行った場合に発生します。

//emlist[例][ruby]{
module
M
end
module
M2
include M
end
module
M
include M2
end
//}...
...を引き継ぐことです。
インクルードは多重継承の代わりに用いられており、 mix-in とも呼びます。

//emlist[例][ruby]{
class C
include FileTest
include Math
end

p C.ancestors

# => [C, Math, FileTest, Object, Kernel]
//}

モジュールの機能追加は、...
...ールのほうが
先に行われます
(上の例の Module#ancestors の結果がメソッド探索の順序です)。

同じモジュールを二回以上 include すると二回目以降は無視されます。

//emlist[例][ruby]{
module
M
end
class C1
include M
end
class C2 < C1
include...

Module#alias_method(new, original) -> Symbol (13.0)

メソッドの別名を定義します。

...メソッドの別名を定義します。

//emlist[例][ruby]{
module
Kernel
alias_method :hoge, :puts # => :hoge
alias_method "foo", :puts # => :foo
end
//}

alias との違いは以下の通りです。

* メソッド名は String または Symbol で指定します
* グローバル...
...ます。

@param original 元のメソッド名。String または Symbol で指定します。

@return 作成したエイリアスのメソッド名を表す Symbol を返します。

@see d:spec/def#alias

//emlist[例][ruby]{
module
Kernel
alias_method :foo, :puts
end

foo "bar" # bar
//}...

Module#alias_method(new, original) -> self (13.0)

メソッドの別名を定義します。

...メソッドの別名を定義します。

//emlist[例][ruby]{
module
Kernel
alias_method :hoge, :puts # => Kernel
end
//}

alias との違いは以下の通りです。

* メソッド名は String または Symbol で指定します
* グローバル変数の別名をつけることはで...
...いメソッド名。String または Symbol で指定します。

@param original 元のメソッド名。String または Symbol で指定します。

@return self を返します。

@see d:spec/def#alias

//emlist[例][ruby]{
module
Kernel
alias_method :foo, :puts
end

foo "bar" # bar
//}...

Module#append_features(module_or_class) -> self (13.0)

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

...ラス)に 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#attr(*name) -> nil (13.0)

インスタンス変数読み取りのためのインスタンスメソッド name を定義します。

...は次の通りです。

//emlist[例][ruby]{
def name
@name
end
//}

第 2 引数 が true で指定された場合には、属性の書き込み用メソッド name= も同時に定義されます。
その定義は次の通りです。

//emlist[例][ruby]{
def name=(val)
@name = val
end
//}...

Module#attr(name, false) -> nil (13.0)

インスタンス変数読み取りのためのインスタンスメソッド name を定義します。

...は次の通りです。

//emlist[例][ruby]{
def name
@name
end
//}

第 2 引数 が true で指定された場合には、属性の書き込み用メソッド name= も同時に定義されます。
その定義は次の通りです。

//emlist[例][ruby]{
def name=(val)
@name = val
end
//}...
<< 1 2 3 ... > >>