编辑代码

#JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
class Car
  attr_accessor :brand

  def initialize brand
    @brand = brand
  end

  private
  def show
    puts "The car is #{@brand}!"
  end

end

car = Car.new("hahah")

car.show # private, then it can not be called.



# Adding a new method to the Person class dynamically
=begin
class Person
  def age
    puts "#{@name} is 25 years old."
  end
end

person.age # Output: Alice is 25 years old.

=end