Skip to content

Instantly share code, notes, and snippets.

@mistyrinth
Created November 24, 2018 09:50
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/76e34c1eab97995eaf45ab4f5594c330 to your computer and use it in GitHub Desktop.
Save mistyrinth/76e34c1eab97995eaf45ab4f5594c330 to your computer and use it in GitHub Desktop.
# クラスの定義
class Pet
# アクセスメソッド
attr_accessor :name
def initialize(petname)
@name = petname
end
def dispName
print(@name, "\n")
end
end
# オブジェクトの作成
pet1 = Pet.new("Bella")
pet1.dispName
# インスタンス変数 @name の値の変更
pet1.name = "John"
pet1.dispName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment