Skip to content

Instantly share code, notes, and snippets.

@mistyrinth
Created November 24, 2018 12:17
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/d9b922098e3b5b3bfcb7748dead66d2f to your computer and use it in GitHub Desktop.
Save mistyrinth/d9b922098e3b5b3bfcb7748dead66d2f to your computer and use it in GitHub Desktop.
# クラスの定義
class Pet
@@count = 0
def initialize(petname="none")
@name = petname
@@count += 1
end
def dispName
print(@name, "\n")
end
def getCount
return @@count
end
end
pet1 = Pet.new("Bella")
pet1.dispName
pet2 = Pet.new("Duke")
pet2.dispName
pet3 = Pet.new("Lucy")
pet3.dispName
print("ペットの数は", pet1.getCount, "です。\n")
# pet1 の部分を pet2 や pet3 に変えても結果は一緒です(^^*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment