摘要:
ruby中有类似vb的模块module如:module Summable def sum inject {|v,n| v+n} endendclass Array include Summableendclass Range include Summableendclass VowelFinder include Summableend[1,2,3,4,5].sum 得到 15('a'..'m') 得到 "abcdefghijklm"vf=VowelFinder.new("the quick brown fox jumped&quo 阅读全文
摘要:
class File def File.Open(*args) result=f=File.new(*args) if block_given? begin result=yield f ensure f.close end return result endend注: ensure用于必定要执行的语句 阅读全文
摘要:
正则表达式的分组在模式内部,\1序列指的是第一个组的匹配,\2序列指的是第二个组的匹配,如irb(main):008:0> "12:50am"=~/(\d\d):(\d\d)(..)/=> 0irb(main):009:0> "Hour is #$1,minute is #$2"=> "Hour is 12,minute is 50"irb(main):010:0> "12:50am"=~/((\d\d):(\d\d))(..)/=> 0irb(main):011:0> & 阅读全文
摘要:
[步骤][功能][说明]Move移动1、将选定的静态函数从一个类移动到另一个类2、将选中的类或接口移动到其他单元Extract Interface抽取接口将选定的函数抽取到一个新的接口Extract Superclass抽取基类将选定的函数、属性、字段从一个类里抽取到一个基类中Pull Member Up将成员向上拉1、将子类中的函数或字段移动到父类2、将子接口中的函数移动到父接口Push Members Down将成员向下推1、将父类中的字段或者函数移动到子类2、将父接口中的函数移动到子接口Safe Delete安全删除在确认没有其他代码调用的情况下,删除所选定的变量、组件、类或接口Inli 阅读全文