るりまサーチ

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

別のキーワード

  1. _builtin using
  2. main using
  3. module using
  4. processcontroller using_at_exit_when_process_exit
  5. shell/process-controller using_at_exit_when_process_exit

ライブラリ

クラス

検索結果

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

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

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

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

メソッドをコピーするため、Rubyコードで...
...e StrUtils
def indent(level)
' ' * level + self
end
end

module M
refine String do
import_methods
StrUtils
end
end

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: Enumer...