るりまサーチ

最速Rubyリファレンスマニュアル検索!
902件ヒット [1-100件を表示] (0.170秒)
トップページ > クエリ:-[x] > クエリ:E[x] > クエリ:ruby[x] > クラス:Module[x]

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method new
  4. irb/input-method gets
  5. matrix -

検索結果

<< 1 2 3 ... > >>

Module#ruby2_keywords(method_name, ...) -> nil (12332.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.

...he 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...
...ment 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 met...
...er methods.

This should only be used for methods that delegate keywords to another
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
be...

Module#private_instance_methods(inherited_too = true) -> [Symbol] (9307.0)

そのモジュールで定義されている private メソッド名 の一覧を配列で返します。

...vate メソッド名
の一覧を配列で返します。

@param inherited_too false を指定するとそのモジュールで定義されているメソッドのみ返します。

@see Object#private_methods, Module#instance_methods

//emlist[例][ruby]{
module
Foo
def foo; end
private def b...
...ar; end
e
nd

module
Bar
include Foo

def baz; end
private def qux; end
e
nd

Bar.private_instance_methods # => [:qux, :bar]
Bar.private_instance_methods(false) # => [:qux]
//}...

Module#class_eval(expr, fname = "(eval)", lineno = 1) -> object (6307.0)

モジュールのコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを 評価してその結果を返します。

...のコンテキストで文字列 expr またはモジュール自身をブロックパラメータとするブロックを
評価してその結果を返します。

モジュールのコンテキストで評価するとは、実行中そのモジュールが self になるということです。...
...つまり、そのモジュールの定義式の中にあるかのように実行されます。

ただし、ローカル変数は module_eval/class_eval の外側のスコープと共有します。

文字列が与えられた場合には、定数とクラス変数のスコープは自身のモ...
...@param expr 評価される文字列。

@param fname 文字列を指定します。ファイル fname に文字列 expr が書かれているかのように実行されます。
スタックトレースの表示などを差し替えることができます。

@param lineno 文字...

Module#instance_methods(inherited_too = true) -> [Symbol] (6237.0)

そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返します。

...ected メソッド名
の一覧を配列で返します。

@param inherited_too false を指定するとそのモジュールで定義されているメソッドのみ返します。

@see Object#methods

//emlist[例1][ruby]{
class Foo
private; def private_foo() end
protected; def protecte...
...d_foo() end
public; def public_foo() end
e
nd

# あるクラスのインスタンスメソッドの一覧を得る
p Foo.instance_methods(false)
p Foo.public_instance_methods(false)
p Foo.private_instance_methods(false)
p Foo.protected_instance_methods(false)

class Bar < Foo
e
nd
//}

実行...
...結果

[:protected_foo, :public_foo]
[:public_foo]
[:private_foo]
[:protected_foo]

//emlist[例2][ruby]{
class Bar
private; def private_foo() end
protected; def protected_foo() end
public; def public_foo() end
e
nd

# あるクラスのインスタンスメソッ...

Module#refine(klass) { ... } -> Module (6231.0)

引数 klass で指定したクラスだけに対して、ブロックで指定した機能を提供で きるモジュールを定義します。定義した機能は Module#refine を使用せずに直 接 klass に対して変更を行う場合と異なり、限られた範囲のみ有効にできます。 そのため、既存の機能を局所的に修正したい場合などに用いる事ができます。

...定義した機能は Module#refine を使用せずに直
接 klass に対して変更を行う場合と異なり、限られた範囲のみ有効にできます。
そのため、既存の機能を局所的に修正したい場合などに用いる事ができます。

refinements 機能の詳細...
...e.rubyist.net/articles/0041/0041-200Special-refinement.html
* https://docs.ruby-lang.org/en/master/syntax/refinements_rdoc.html

定義した機能は main.using, Module#using を実行した場合のみ
有効になります。

@param klass 拡張する対象のクラスを指定します。

@re...
...機能を持つ無名のモジュールを返します。


//emlist[例][ruby]{
class C
def foo
puts "C#foo"
e
nd
e
nd

module
M
refine C do
def foo
puts "C#foo in M"
e
nd
e
nd
e
nd

x = C.new
x.foo # => "C#foo"

using M

x = C.new
x.foo # => "C#foo in M"
//}

@see main.using...
...いては以下を参照してください。

* https://magazine.rubyist.net/articles/0041/0041-200Special-refinement.html
* https://docs.ruby-lang.org/en/master/syntax/refinements_rdoc.html

定義した機能は main.using, Module#using を実行した場合のみ
有効になります。

@par...
...

@return ブロックで指定した機能を持つ無名のモジュールを返します。


//emlist[例][ruby]{
class C
def foo
puts "C#foo"
e
nd
e
nd

module
M
refine C do
def foo
puts "C#foo in M"
e
nd
e
nd
e
nd

x = C.new
x.foo # => "C#foo"

using M

x = C.new
x.foo...

絞り込み条件を変える

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

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

...od Module のインスタンス( Enumerable など)を指定します。

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

//emlist[例][ruby]{
module
M
e
nd
module
M2
include M
e
nd
module
M
include M2
e
nd
//}

実行結果:

-
:...
...3:in `append_features': cyclic include detected (ArgumentError)
from -:3:in `include'
from -:3


インクルードとは、指定されたモジュールの定義
(メソッド、定数) を引き継ぐことです。
インクルードは多重継承の代わりに用いられ...
...ており、 mix-in とも呼びます。

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

p C.ancestors

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

モジュールの機能追加は、クラスの継承関係の間にそのモジュールが挿入
されることで実現さ...

Module#instance_method(name) -> UnboundMethod (6225.0)

self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。

...self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。

@param name メソッド名を Symbol または String で指定します。

@raise NameError self に存在しないメソッドを指定した場合に発生します。

@see Module#publ...
...tance_method, Object#method

//emlist[例][ruby]{
class Interpreter
def do_a() print "there, "; end
def do_d() print "Hello "; end
def do_e() print "!\n"; end
def do_v() print "Dave"; end
Dispatcher = {
"a" => instance_method(:do_a),
"d" => instance_method(:do_d),
"e" =...
...> instance_method(:do_e),
"v" => instance_method(:do_v)
}
def interpret(string)
string.each_char {|b| Dispatcher[b].bind(self).call }
e
nd
e
nd

interpreter = Interpreter.new
interpreter.interpret('dave')
# => Hello there, Dave!
//}...

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

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

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

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

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

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

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

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

@see d:spec/def#alias

//emlist[例][ruby]{...
...module Kernel
alias_method :foo, :puts
e
nd

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

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

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

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

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

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

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

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

@return self を返します。

@see d:spec/def#alias

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

foo...

Module#append_features(module_or_class) -> self (6213.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)
e
nd
e
nd
//}

@see Module#included...

絞り込み条件を変える

Module#attr_accessor(*name) -> [Symbol] (6213.0)

インスタンス変数 name に対する読み取りメソッドと書き込みメソッドの両方を 定義します。

...変数 name に対する読み取りメソッドと書き込みメソッドの両方を
定義します。

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

...
...ドで定義されるメソッドの定義は以下の通りです。

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

@param name String または Symbol を 1 つ以上指定します。
@return 定義されたメソッド名を Symbol の配列で返します。...

Module#attr_reader(*name) -> [Symbol] (6213.0)

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

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

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

このメソッドで定義されるメソッドの定義...
...は以下の通りです。

//emlist[例][ruby]{
def name
@name
e
nd
//}

@param name String または Symbol を 1 つ以上指定します。
@return 定義されたメソッド名を Symbol の配列で返します。...

Module#attr_writer(*name) -> [Symbol] (6213.0)

インスタンス変数 name への書き込みメソッド (name=) を定義します。

...インスタンス変数 name への書き込みメソッド (name=) を定義します。

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

このメソッドで定義されるメソ...
...ッドの定義は以下の通りです。

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

@param name String または Symbol を 1 つ以上指定します。
@return 定義されたメソッド名を Symbol の配列で返します。...
<< 1 2 3 ... > >>