< Shape do var :width var :height def area do this.width * this.height end end class Square < Rectangle do def area do :math.pow(this.width, 2) end end
end class Comment < ActiveRecord.Base do end Post.new Comment.new ActiveRecord.Base.new ** (RuntimeError) cannot instantiate abstract class ActiveRecord.Base
end end class AppleInc do private_var :devices end apple = Apple.new(devices: ["Alice's iPhone", "Bob's iPad”]) NSA.new.get_data(apple) ** (RuntimeError) Cannot access private var devices
end end class AppleInc do friend NSA private_var :devices end apple = Apple.new(devices: ["Alice's iPhone", "Bob's iPad”]) NSA.new.get_data(apple) # => ["Alice's iPhone", "Bob's iPad"]