definded? and safe_constantize

a = 1

defined? a => "local-variable"

defined? b => nil

'hello'.gsub(/正则表达式/, '替换的值')  gsub方法的用法就用将一个字符串去匹配参数一中的正则表达式,用第二个参数的值去替换匹配出的字符

'  hell0  '.strip  表示去除字符串前后的空格

'hello'.is_a(String) 是判断'hello'是不是String类的一个实例

'Hello'.downcase   将这个字符串中的大写字母转为小写

'Hello'.tableize 将这个字符串转为表的名字比如 'Hello'.tableize--> hellos

Object.freeze 冻结,不能修改的

Object.dup  浅拷贝一份Object对象

'corp'.camelize.safe_constantize.new      == Corp.new

'corp'.camelize.safe_constantize.where == Corp.where

原文地址:https://www.cnblogs.com/qinyan20/p/3657103.html