るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.037秒)
トップページ > クラス:Module[x] > 種類:インスタンスメソッド[x] > クエリ:Kernel.#require[x]

別のキーワード

  1. kernel exec
  2. kernel system
  3. kernel spawn
  4. kernel open
  5. kernel raise

ライブラリ

検索結果

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

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

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

const_name が autoload 設定されていて、まだ定義されてない(ロードされていない)ときは、
autoload する対象を置き換えます。
const_name が(autoload...
...含めることはできません。
つまり、self の直下に定義された定数しか指定できません。

@param feature Kernel.#require と同様な方法で autoload する対象を指定する。

//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class Foo
class Bar
end...
...nstant Bar referenced by Foo::Bar
# Bar
# nil
//}

これは以下のようにネストせずに定義したのと同じことです。

//emlist[例][ruby]{
class Foo
end
class Bar
end
p Foo::Bar
#=> -:5: warning: toplevel constant Bar referenced by Foo::Bar
# Bar
//}

@see Kernel.#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...