LoginSignup
3
3

More than 5 years have passed since last update.

Ruby | Kernelにdefメソッドを定義してみる

Posted at

Kernelにdefメソッドを定義してみる

特に意味はありませんが Kernel module に def メソッドを定義してみます。

サンプルコード

module Kernel
  def def(msg)
    "my def #{msg}"
  end
end

print send :def, 'args' # => 'my def args'

# 通常の def キーワードと判断されて使えない
# def 'hoge'

結果

  • メソッドの定義は問題なくできる
  • sendで呼び出せば問題なく動作する
  • 直接呼び出そうとすると def キーワードと判断され end がないため syntax error が発生
3
3
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
3
3