Skip to content

Instantly share code, notes, and snippets.

@tadaken3
Created August 2, 2016 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadaken3/e6832914d4a4c62f8052f0730fcee97e to your computer and use it in GitHub Desktop.
Save tadaken3/e6832914d4a4c62f8052f0730fcee97e to your computer and use it in GitHub Desktop.
インスタンスメソッド内でのself変数の扱い ref: http://qiita.com/tadaken3/items/266448d3f773211f69e3
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