るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.054秒)

別のキーワード

  1. kernel $error_info
  2. kernel $last_match_info
  3. kernel $process_id
  4. kernel $last_read_line
  5. kernel $load_path

ライブラリ

検索結果

Module#autoload(const_name, feature) -> nil (51.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...