1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Ruby】const_missingメソッドについて

Posted at
class Object
  X = "X"
  def self.const_missing a
    p "#{a}"
  end
end
Y

> "Y"

const.missing

const_missingは、未定義の定数を参照した場合に呼び出される。
この場合は、Yは定数として定義していないため、const_missingが呼び出され実行される。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?