LoginSignup
1
0

More than 1 year has passed since last update.

Ruby | クラスをメソッドにする方法 (メタプログラミングRuby)

Last updated at Posted at 2018-06-14

大文字をメソッドとして定義する。

def A(arg)
  p arg
end

普通にクラスを呼ぶと、クラスとして解釈される。

A # NameError: uninitialized constant A

引数を渡すとメソッドと解釈される。

A 'mimic!' # "mimic!"

環境

  • ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

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