my first ruby code

快放假了,工作终于少了下来,一口气看了几篇ruby文档,凑了一个小程序玩玩。

funny ruby code in intype

 

ruby 代码
  1. class Person   
  2.   
  3.     def initialize(name="God")   
  4.         @name = name   
  5.     end  
  6.   
  7.     attr_accessor :name  
  8.     attr_accessor :sex  
  9.     attr_accessor :age  
  10.   
  11.     def die   
  12.         if @age<20   
  13.             puts "oh my god! died now ... at #{@age} ..."  
  14.         elsif @age>70   
  15.             puts "ok...god say that's enough ... at #{@age} ..."  
  16.         else  
  17.             puts "died now ... at #{@age} ..."  
  18.         end    
  19.     end  
  20.   
  21.     def borth   
  22.         @age = 0   
  23.         puts "#{@name} come to the world, let's say hello to him."  
  24.     end  
  25.   
  26.     def get_older   
  27.         @age+=1   
  28.         puts "get old #{@age}"  
  29.     end  
  30.   
  31. end  
  32.   
  33. #if the file is executable   
  34.   
  35. if __FILE__ == $0  
  36.     my = Person.new "linnchord"  
  37.     my.borth   
  38.   
  39.     70.times do  
  40.         my.get_older   
  41.     end  
  42.   
  43.     my.die   
  44. end  

simple and funny script language

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值