Skip to content

Instantly share code, notes, and snippets.

@mistyrinth
Created November 24, 2018 07:54
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 mistyrinth/cfc4f4366f4b2071c5bacc43e01d7c5c to your computer and use it in GitHub Desktop.
Save mistyrinth/cfc4f4366f4b2071c5bacc43e01d7c5c to your computer and use it in GitHub Desktop.
# クラスの定義
class Pet
def setName(petname)
@name = petname
end
def dispName
print(@name, "\n")
end
end
# オブジェクトの作成
pet1 = Pet.new()
pet1.setName("Bella")
pet2 = Pet.new()
pet2.setName("Duke")
# pet1のインスタンス変数 @name を出力
pet1.dispName
# pet2のインスタンス変数 @name を出力
pet2.dispName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment