Created
December 20, 2014 01:57
-
-
Save k2works/6cc0973a2943e8e70eaa 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
# coding: utf-8 | |
class Foo | |
end | |
foo = Foo.new | |
bar = Foo.new | |
# barだけにメソッドを定義する | |
def bar.singleton_method | |
puts 'Called!' | |
end | |
# singleton_methodはbarに対してだけ呼べる | |
bar.singleton_method # >> Called! | |
foo.singleton_method # ~> -:14:in `singleton_method': wrong number of arguments (0 for 1) (ArgumentError) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment