您的位置:首页 > Web前端

definded? and safe_constantize

2014-04-10 17:59 162 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: