Created
June 7, 2014 07:45
-
-
Save serco-chen/d6a0afc30d10314f431c to your computer and use it in GitHub Desktop.
Xiaobai Toothbrush
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A1 # A1 声波牙刷 | |
FEATURES = [ | |
"五档位调节, 20000 ~ 36000 次/分钟;", | |
"2分钟自动关闭, 档位记忆, 下次使用自动进入上一次选择档位;", | |
"感应式充电,一次充电可稳定使用30次以上;", | |
"标配4个可更换刷头" | |
] | |
@@questions = ["使用方法", "清洁方法", "保修电话"] | |
def initialize(purchase_date: Time.now, **options) | |
@purchase_date = purchase_date | |
end | |
def in_warranty? | |
(Time.now.to_i - @purchase_date.to_i) < 3600*24*365 # 一年质保 | |
end | |
def features | |
FEATURES.map.with_index {|feature, index| (feature.reverse << " .#{index+1}").reverse }.join("\n") | |
end | |
def method_missing(name, *args, &block) | |
unless @@questions.include? name.to_s | |
@@questions << name.to_s | |
puts "不明白您的意思,请再说一遍好吗" | |
super | |
end | |
puts name.to_s + "请见产品说明书以及产品包装内的保修卡,或直接致电与我们联系,谢谢" | |
end | |
end | |
## 小白牙刷调戏方法如下 | |
## Mac OS X 10.8 以上用户请直接在shell中输入 irb 进入 | |
## Linux 用户请自行安装 Ruby 2.0 以上版本 | |
## Windows 用户请换台 Mac | |
## 创造一支小白 | |
## 引入本文件 require '/path/to/this/file' | |
# require '/Users/username/xiaobai' | |
# 小白 = A1.new | |
## 常规问题 | |
# puts 小白.in_warranty? | |
# puts 小白.features | |
# puts 小白.使用方法 | |
## 随便问什么 | |
# puts 小白.电池能用多久啊? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@supgeek-rod http://www.v2ex.com/t/116249
只是用来玩的。