るりまサーチ

最速Rubyリファレンスマニュアル検索!
17件ヒット [1-17件を表示] (0.180秒)
トップページ > クエリ:_builtin[x] > ライブラリ:ビルトイン[x] > クエリ:E[x] > クエリ:Refinement[x]

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

クラス

キーワード

検索結果

Refinement (52008.0)

refine のブロックの中の self のクラスです。

...refine のブロックの中の self のクラスです。

Refinement
#import_methodsで他のモジュールからメソッドを
インポートできます。...

Refinement#import_methods(*modules) -> self (35114.0)

モジュールからメソッドをインポートします。

...モジュールからメソッドをインポートします。

Module#includeと違って、import_methods はメソッドをコピーして
refinement
に追加して、refinementでインポートしたメソッドを有効化します。

メソッドをコピーするため、Rubyコードで...
...//emlist[][ruby]{
module StrUtils
def indent(level)
' ' * level + self
e
nd
e
nd

module M
refine String do
import_methods StrUtils
e
nd
e
nd

using M
p "foo".indent(3) # => " foo"

module M
refine String do
import_methods Enumerable
# Can't import method which is not defined...
...with Ruby code: Enumerable#drop
e
nd
e
nd
//}...

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

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

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

refinement
s 機能の詳細につ...
...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...