my first ruby code

系统 1438 0

快放假了,工作终于少了下来,一口气看了几篇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

my first ruby code


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论