Last active
July 6, 2019 11:26
-
-
Save TomohikoSato/deab70beb82b2353cc3d98389a90858e to your computer and use it in GitHub Desktop.
クラス/メソッドの定義
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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