るりまサーチ

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

別のキーワード

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

ライブラリ

キーワード

検索結果

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

...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 in...
...st in Ruby versions
before 2.7, check that the module responds to this method before calling
it. Also, be 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(:...

Module#===(obj) -> bool (119.0)

指定された obj が self かそのサブクラスのインスタンスであるとき真を返します。 また、obj が self をインクルードしたクラスかそのサブクラスのインスタンスである場合にも 真を返します。上記のいずれでもない場合に false を返します。

...スタンスである場合にも
真を返します。上記のいずれでもない場合に false を返します。

言い替えると obj.kind_of?(self) が true の場合、 true を返します。

このメソッドは主に case 文での比較に用いられます。
case ではクラス...
...ルの所属関係をチェックすることになります。

//emlist[例][ruby]{
str = String.new
case str
when String # String === str を評価する
p true # => true
end
//}

@param obj 任意のオブジェクト

@see Object#kind_of?, Object#instance_of?, d:spec/control#case...

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

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

... ------- /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]{
# ---...
...---- /tmp/foo.rb ---------
class Foo
class Bar
end
end
# ----- end of /tmp/foo.rb ----

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

以下のように、autoload したライブラリがネストした定数を定義しない場
合、一見、正常に動作して...
...(警告メッ
セージが出ています)。

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

class Foo
autoload :Bar, '/tmp/bar.rb'
end
p Foo::Bar
p Foo.autoload?(:Bar)
#=> -:4: warning: toplevel constant Bar referenced by Foo::Bar
# Bar
#...
...---- /tmp/foo.rb ---------
class 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#const_set(name, value) -> object (107.0)

モジュールに name で指定された名前の定数を value とい う値として定義し、value を返します。

...@param name Symbol,String で定数の名前を指定します。
@param value セットしたい値を指定します。

//emlist[例][ruby]{
module
Foo; end

# Symbolを指定した場合
Foo.const_set(:FOO, 123)
Foo::FOO # => 123

# Stringを指定した場合
Foo.const_set('BAR', 'abc')
Foo:...
...れている定数の名前を指定した場合
Foo.const_set('BAR', '123')
# warning: already initialized constant Foo::BAR
# warning: previous definition of BAR was here
# => "123"

# 不適切な定数名を指定した場合
Foo.const_set('foo', 1) # => NameError: wrong constant name foo
//}...