def validate(object)
      # Handle nil case.
      if object.nil?
        if allow_nil?
          self.sanitized_object = nil
          return true
        else
          raise ValidationError, "object is nil but this #{self.class} does not allow nil"
        end
      end
      # Validate object format.
      unless object.is_a?(Hash)
        raise ValidationError, "object is not a hash but a #{object.class}"
      end
      sanitized_object = {}.with_indifferent_access
      # Validate expected properties.
      @properties.each do |name, schema|
        case name
        when Symbol
          validate_property_with_options(name.to_s, schema, object, sanitized_object)
        when String
          validate_property_with_options(name, schema, object, sanitized_object)
        when Regexp
          object.select{|prop, schema| prop =~ name }.each do |prop, value|
            validate_property(prop, schema, object, sanitized_object)
          end
        end
      end
      if options[:strict]
        # Check whether there are extra properties.
        object.each do |name, schema|
          unless sanitized_object.has_key? name
            raise ValidationError, "unexpected key `#{name}'"
          end
        end
      end
      self.sanitized_object = sanitized_object
      true
    rescue ValidationError => e
      # Reset sanitized object.
      self.sanitized_object = nil
      raise e
    end
def validate(object)
      # Handle nil case.
      if object.nil?
        if allow_nil?
          self.sanitized_object = nil
          return true
        else
          raise ValidationError, "object is nil but this #{self.class} does not allow nil"
        end
      end
      # Validate object format.
      unless object.is_a?(Hash)
        raise ValidationError, "object is not a hash but a #{object.class}"
      end
      sanitized_object = {}.with_indifferent_access
      # Validate expected properties.
      @properties.each do |name, schema|
        case name
        when Symbol
          validate_property_with_options(name.to_s, schema, object, sanitized_object)
        when String
          validate_property_with_options(name, schema, object, sanitized_object)
        when Regexp
          object.select{|prop, schema| prop =~ name }.each do |prop, value|
            validate_property(prop, schema, object, sanitized_object)
          end
        end
      end
      if options[:strict]
        # Check whether there are extra properties.
        object.each do |name, schema|
          unless sanitized_object.has_key? name
            raise ValidationError, "unexpected key `#{name}'"
          end
        end
      end
      self.sanitized_object = sanitized_object
      true
    rescue ValidationError => e
      # Reset sanitized object.
      self.sanitized_object = nil
      raise e
    end
Overwritten method. See {Schema#validate}.