Skip to content

Instantly share code, notes, and snippets.

@TomohikoSato
Last active July 6, 2019 11:26
Show Gist options
  • Save TomohikoSato/deab70beb82b2353cc3d98389a90858e to your computer and use it in GitHub Desktop.
Save TomohikoSato/deab70beb82b2353cc3d98389a90858e to your computer and use it in GitHub Desktop.
クラス/メソッドの定義
# https://magazine.rubyist.net/articles/0046/0046-SingletonClassForBeginners.html
# https://docs.ruby-lang.org/ja/2.1.0/doc/spec=2fdef.html#class_method
# クラス定義
class Hoge
def Hoge.foo
p "foo"
end
end
Hoge.foo # foo
# 特異クラス
obj = nil
class << obj
def test
p "test"
end
end
obj.test # "test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment