# bad (+ a warning)ifv=array.grep(/foo/)do_something(v)...end# good (MRI would still complain, but RuboCop won't)if(v=array.grep(/foo/))do_something(v)...end# goodv=array.grep(/foo/)ifvdo_something(v)...end

用 proc 而不是 Proc.new。

12345

# badp=Proc.new{|n|putsn}# goodp=proc{|n|putsn}

类与模块

在 class 定义里使用一致的结构。

123456789101112131415161718192021222324252627282930313233

classPerson# extend and include go firstextendSomeModuleincludeAnotherModule# constants are nextSOME_CONSTANT=20# afterwards we have attribute macrosattr_reader:name# followed by other macros (if any)validates:name# public class methods are next in linedefself.some_methodend# followed by public instance methodsdefsome_methodend# protected and private methods are grouped near the endprotecteddefsome_protected_methodendprivatedefsome_private_methodendend