ruby class attribute

[1] pry(main)> class A
[1] pry(main)*   class << self
[1] pry(main)*     attr_accessor :a
[1] pry(main)*     def set_a(b)
[1] pry(main)*       @a=b
[1] pry(main)*     end  
[1] pry(main)*     def show_a
[1] pry(main)*       @a
[1] pry(main)*     end  
[1] pry(main)*   end  
[1] pry(main)* end  
=> :show_a
[2] pry(main)> A.set_a(100)
=> 100
[3] pry(main)> A.show_a
=> 100
[4] pry(main)> A.a
=> 100
[5] pry(main)>

你可能感兴趣的:(ruby class attribute)