class BSON::Code

JavaScript code to be evaluated by MongoDB.

Attributes

code[RW]

Hash mapping identifiers to their values

scope[RW]

Hash mapping identifiers to their values

Public Class Methods

new(code, scope={}) click to toggle source

Wrap code to be evaluated by MongoDB.

@param [String] code the JavaScript code. @param [Hash] scope a document mapping identifiers to values, which

represent the scope in which the code is to be executed.
# File lib/bson/types/code.rb, line 28
def initialize(code, scope={})
  @code  = code
  @scope = scope

  unless @code.is_a?(String)
    raise ArgumentError, "BSON::Code must be in the form of a String; #{@code.class} is not allowed."
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/bson/types/code.rb, line 41
def ==(other)
  self.class == other.class &&
    @code == other.code && @scope == other.scope
end
inspect() click to toggle source
# File lib/bson/types/code.rb, line 46
def inspect
  "<BSON::Code:#{object_id} @data=\"#{@code}\" @scope=\"#{@scope.inspect}\">"
end
length() click to toggle source
# File lib/bson/types/code.rb, line 37
def length
  @code.length
end
to_bson_code() click to toggle source
# File lib/bson/types/code.rb, line 50
def to_bson_code
  self
end