快放假了,工作终于少了下来,一口气看了几篇ruby文档,凑了一个小程序玩玩。
funny ruby code in intype
ruby 代码
- class Person
- def initialize(name= "God" )
- @name = name
- end
- attr_accessor :name
- attr_accessor :sex
- attr_accessor :age
- def die
- if @age <20
- puts "oh my god! died now ... at #{@age} ..."
- elsif @age >70
- puts "ok...god say that's enough ... at #{@age} ..."
- else
- puts "died now ... at #{@age} ..."
- end
- end
- def borth
- @age = 0
- puts "#{@name} come to the world, let's say hello to him."
- end
- def get_older
- @age +=1
- puts "get old #{@age}"
- end
- end
- #if the file is executable
- if __FILE__ == $0
- my = Person. new "linnchord"
- my.borth
- 70.times do
- my.get_older
- end
- my.die
- end
simple and funny script language