インスタンス変数を読み書きするときのメモ。
attr_accessor (Module) - Rubyリファレンス
# -*- coding: utf-8 -*- class Book attr_accessor :price attr_reader :title attr_writer :desc def initialize(title, price, desc) @title = title; @price = price; @desc = desc end end book = Book.new("Programming Ruby", 1980, "hogehoge") puts book puts book.title puts book.price book.price = 2000 puts book.price # book.title = "Programming Perl" # NoMethodError book.desc = "Programming Perl" # puts book.desc # NoMethodError class Foo1 @foo1 = 'foo' # 間違った書き方 @@foo1 = 1 def inst_foo puts @foo end def inst_fooMK2 @foo1 = 'foo' puts @foo1 end def class_foo puts @@foo1 end end foo1 = Foo1.new foo1.inst_foo # nil foo1.inst_fooMK2 # foo foo1.class_foo # 1