Ruby 控制结构与 Rails 环境及数据库配置详解
1. Ruby 控制结构
在 Ruby 中,为了演示控制结构,我们先定义一些汽车类,代码如下:
class Car
@@wheels = 4 # class variable
@@number_of_cars = 0 # class variable
def initialize
@@number_of_cars = @@number_of_cars + 1
end
def self.count
@@number_of_cars
end
def mileage=(x) # instance variable writer
@mileage = x
end
def mileage # instance variable reader
@mileage
end
end
class StretchLimo < Car
@@wheels = 6 # class variable
@@televisions = 1 # class variable
def turn_on_television
# Invoke code for switching on on-board TV here
end
end
class PontiacFirebird < Car
end
class VolksWagen < Car
end
超级会员免费看
订阅专栏 解锁全文
15

被折叠的 条评论
为什么被折叠?



