LoginSignup
1
2

More than 5 years have passed since last update.

インスタンス変数に外からアクセスするメソッドを簡単に書く

Posted at

その2
インスタンス変数に外からアクセスするメソッドを簡単に書く
attr_accessor インスタンス変数名のシンボル

class AClass
def initialize
  @foo
  @bar
end

attr_accesor :foo,:bar
end

instance = AClass.new
instance.foo = 1
instance.bar = "bar"
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2