fork download
  1.  
  2. class A
  3. attr_accessor :x
  4. def initialize
  5. @x = 0
  6. end
  7. def f # @xにはアクセスしたくないメソッド
  8. @x
  9. end
  10. def f2
  11. @x += 1
  12. end
  13. end
  14. a = A.new
  15. p 5.times.map{a.f2}
  16. p a.f #=> 5
Success #stdin #stdout 0s 6560KB
stdin
Standard input is empty
stdout
[1, 2, 3, 4, 5]
5