    # File lib/active_record/validations.rb, line 557
          def validates_length_of(*attrs)
            # Merge given options with defaults.
            options = {
              :tokenizer => lambda {|value| value.split(//)}
            }.merge(DEFAULT_VALIDATION_OPTIONS)
            options.update(attrs.extract_options!.symbolize_keys)

            # Ensure that one and only one range option is specified.
            range_options = ALL_RANGE_OPTIONS & options.keys
            case range_options.size
              when 0
                raise ArgumentError, 'Range unspecified.  Specify the :within, :maximum, :minimum, or :is option.'
              when 1
                # Valid number of options; do nothing.
              else
                raise ArgumentError, 'Too many range options specified.  Choose only one.'
            end

            # Get range option and value.
            option = range_options.first
            option_value = options[range_options.first]
            key = {:is => :wrong_length, :minimum => :too_short, :maximum => :too_long}[option]
            custom_message = options[:message] || options[key]

            case option
              when :within, :in
                raise ArgumentError, ":#{option} must be a Range" unless option_value.is_a?(Range)

                validates_each(attrs, options) do |record, attr, value|
                  value = options[:tokenizer].call(value) if value.kind_of?(String)
                  if value.nil? or value.size < option_value.begin
                    record.errors.add(attr, :too_short, :default => custom_message || options[:too_short], :count => option_value.begin)
                  elsif value.size > option_value.end
                    record.errors.add(attr, :too_long, :default => custom_message || options[:too_long], :count => option_value.end)
                  end
                end
              when :is, :minimum, :maximum
                raise ArgumentError, ":#{option} must be a nonnegative Integer" unless option_value.is_a?(Integer) and option_value >= 0

                # Declare different validations per option.
                validity_checks = { :is => "==", :minimum => ">=", :maximum => "<=" }

                validates_each(attrs, options) do |record, attr, value|
                  value = options[:tokenizer].call(value) if value.kind_of?(String)
                  unless !value.nil? and value.size.method(validity_checks[option])[option_value]
                    record.errors.add(attr, key, :default => custom_message, :count => option_value)
                  end
                end
            end
          end