模块:Mongoid::Extensions::Object

定义于:
lib/mongoid/extensions/ 对象.rb

Overview

为 Object 类添加类型转换行为。

在命名空间下定义

模块: 类方法

类方法摘要折叠

实例方法摘要折叠

类方法详细信息

included (base) ⇒对象



8
9
10
# File 'lib/mongoid/extensions/ 对象.rb', line 8

def self.包含(基础)
  基础.扩展(类方法)
end

实例方法详细信息

# __evolve_object_id__对象也称为: __mongoize_object_id__

将普通对象演进为对象ID。

例子:

演进对象。

object.__evolve_object_id__

返回:



18
19
20
# File 'lib/mongoid/extensions/ 对象.rb', line 18

def __evolve_object_id__
  self
end

# __find_args__ ">对象

已弃用。

将对象转换为查找查询的参数。

例子:

将对象转换为 args。

object.__find_args__

返回:



30
31
32
# File 'lib/mongoid/extensions/ 对象.rb', line 30

def __find_args__
  self
end

# __setter__string

已弃用。

尝试从此对象形成 setter。

例子:

尝试构建一个 setter。

object.__setter__

返回:

  • ( string )

    string加 = 形式的对象。



42
43
44
# File 'lib/mongoid/extensions/ 对象.rb', line 42

def __setter__
  " #{ self } = "
end

# __sortable__ ">对象

已弃用。

获取对象的值作为mongo友好的排序值。

例子:

获取对象作为排序条件。

object.__sortable__

返回:



54
55
56
# File 'lib/mongoid/extensions/ 对象.rb', line 54

def __sortable__
  self
end

# __to_inc__对象

已弃用。

将对象转换为 $inc-able 值。

例子:

转换对象。

1.__to_inc__

返回:



66
67
68
# File 'lib/mongoid/extensions/ 对象.rb', line 66

def __to_inc__
  self
end

# do_or_do_not (name, *args) ⇒对象| nil

已弃用。

做或不做,没有尝试。 – 尤达 (Yoda)。

例子:

做或不做。

object.do_or_do_not(:use, "The Force")

参数:

返回:

  • ( Object | nil )

    方法调用的结果,如果该方法不存在,则返回 nil。



83
84
85
# File 'lib/mongoid/extensions/ 对象.rb', line 83

def do_or_do_not(名称, *args)
  发送(名称, *args) if 名称 && respond_to?(名称)
end

# ivar (name) ⇒对象| false

获取实例变量的值,如果不存在,则返回 false。

例子:

获取实例变量的值。

document.ivar("person")

参数:

  • 名称 ( string )

    变量的名称。

返回:

  • ( Object | false )

    该值或 false。



96
97
98
99
100
101
102
103
# File 'lib/mongoid/extensions/ 对象.rb', line 96

def ivar(名称)
  var_name = " @_ #{ name } "
  if instance_variable_defined?(var_name)
    return instance_variable_get(var_name)
  else
    false
  end
end

# mongoize对象

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

例子:

将对象 Mongoize。

object.mongoize

返回:



112
113
114
# File 'lib/mongoid/extensions/ 对象.rb', line 112

def mongoize
  self
end

# multi_arged?false

已弃用。

对象是否为多个参数。

例子:

对象是否为多个参数?

object.multi_arged?

返回:

  • ( false )

    false。



123
124
125
# File 'lib/mongoid/extensions/ 对象.rb', line 123

def multi_arged?
  false
end

# numeric?false

对象是数字吗?

例子:

对象是数字吗?

object.numeric?

返回:

  • ( false )

    始终为 false。



134
135
136
# File 'lib/mongoid/extensions/ 对象.rb', line 134

def numeric?
  false
end

# remove_ivar (name) ⇒ true | false

删除所提供名称的实例变量。

例子:

删除实例变量

document.remove_ivar("person")

参数:

  • 名称 ( string )

    变量的名称。

返回:

  • ( true | false )

    如果已定义变量。



146
147
148
149
150
151
152
# File 'lib/mongoid/extensions/ 对象.rb', line 146

def remove_ivar(名称)
  if instance_variable_defined?(" @_ #{ name } ")
    return remove_instance_variable(" @_ #{ name } ")
  else
    false
  end
end

#可调整大小?false

对象的大小是否可以更改? 当前仅对数组和哈希返回 true。

例子:

对象的大小是否可调整?

object.resizable?

返回:

  • ( false )

    false。



161
162
163
# File 'lib/mongoid/extensions/ 对象.rb', line 161

def 可调整大小?
  false
end

# 可替换对象

获取对象的可替换版本。

例子:

获取替代项。

object.substitutable

返回:



171
172
173
# File 'lib/mongoid/extensions/ 对象.rb', line 171

def 可替换的
  self
end

# you_must (name, *args) ⇒对象| nil

已弃用。

你必须忘掉你所学到的东西。 – 尤达 (Yoda)

例子:

您必须执行此执行。

object.you_must(:use, "The Force")

参数:

返回:

  • ( Object | nil )

    方法调用的结果,如果该方法不存在,则返回 nil。 如果对象被冻结,则为 Nil。



186
187
188
# File 'lib/mongoid/extensions/ 对象.rb', line 186

def you_must(名称, *args)
  冻结? ? nil : do_or_do_not(名称, *args)
end