StyleGuide
RubyStyleGuide
error
catch/throw allows you to quickly exit blocks back to a point where a catch is defined for a specific symbol, raise rescue is the real exception handling stuff involving the Exception object.
raise_rescue
raise SomeException, 'message'
# 捕获异常返回 nil
do_something rescue nildef method
# run code
rescue Timeout::Error
# do something ...
rescue => ex
# do something ...
endthrow_catch
def throw_some
throw :some,'some_throw'
endswap var
数组
flatten
获取
||=
||=&&=
&&=如果存在则赋值
解构
Class
Class definitions
Classstructrue
Classnamespace
to_s
Always supply a proper to_s method for classes that represent domain objects.
Module
module_function
Hash
获取
转换
Number
String
引号
new
拼接
When you need to construct large data chunks, use String#<<. String#+ creates a bunch of new string objects.
同时也不应该在长字符串中使用+,因为这会创建多个字符串
长字符替换
替换
匹配
ruby 中的 Regex
RailsStyleGuide
Macro Style Methods
最后更新于
这有帮助吗?