Created
August 2, 2016 13:28
-
-
Save tadaken3/e6832914d4a4c62f8052f0730fcee97e to your computer and use it in GitHub Desktop.
インスタンスメソッド内でのself変数の扱い ref: http://qiita.com/tadaken3/items/266448d3f773211f69e3
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
class HelloWorld | |
def initialize(myname='Ruby') | |
@name = myname | |
end | |
def hello | |
puts "Hello ,world. I am #{@name}." | |
end | |
def hello2 | |
self.hello #インスタンスメソッドのhelloが呼ばれる | |
end | |
end | |
bob = HelloWorld.new('Bob') | |
bob.hello #=> Hello ,world. I am Bob. | |
bob.hello2 #=> Hello ,world. I am Bob. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment