模块:Mongoid::Extensions::Regexp::ClassMethods

定义于:
lib/mongoid/extensions/regexp.rb

实例方法摘要折叠

实例方法详细信息

# mongoize (object) ⇒ Regexp | nil也称为: demogoize

将对象从我们处理的Ruby类型转换为mongo友好类型。

例子:

将对象 Mongoize。

Regexp.mongoize(/\A[abc]/)

参数:

  • 对象 ( Object )

    要 mongoize 的对象。

返回:

  • ( Regexp | nil )

    对象mongoized 或 nil。



21
22
23
24
25
26
27
28
29
30
# File 'lib/mongoid/extensions/regexp.rb', line 21

def mongoize(对象)
  return if 对象.nil?
  案例 对象
  when 字符串 then ::regexp.new(对象)
  when ::regexp then 对象
  when BSON::regexp::原始 then 对象.编译
  end
救援 RegexpError
  nil
end