Class: String

Overview

Enhance the String class with a XML escaped character version of to_s.

Instance Method Summary collapse

Methods included from ActiveSupport::CoreExtensions::String::OutputSafety

#add_with_safety, #concat_with_safety, #html_safe!, #html_safe?, included

Methods included from ActiveSupport::CoreExtensions::String::Multibyte

#chars, #is_utf8?, #mb_chars

Methods included from ActiveSupport::CoreExtensions::String::Behavior

#acts_like_string?

Methods included from ActiveSupport::CoreExtensions::String::Iterators

append_features, #each_char

Methods included from ActiveSupport::CoreExtensions::String::StartsEndsWith

append_features, #ends_with?, #starts_with?

Methods included from ActiveSupport::CoreExtensions::String::Inflections

#camelize, #classify, #constantize, #dasherize, #demodulize, #foreign_key, #humanize, #parameterize, #pluralize, #singularize, #tableize, #titleize, #underscore

Methods included from ActiveSupport::CoreExtensions::String::Filters

#squish, #squish!

Methods included from ActiveSupport::CoreExtensions::String::Conversions

#ord, #to_date, #to_datetime, #to_time

Methods included from ActiveSupport::CoreExtensions::String::Access

#at, #first, #from, #last, #to

Instance Method Details

#as_json(options = nil) ⇒ Object

:nodoc:



6
7
8
# File 'lib/active_support/json/encoders/string.rb', line 6

def as_json(options = nil) #:nodoc:
  self
end

#blank?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/active_support/core_ext/object/blank.rb', line 49

def blank?
  self !~ /\S/
end

#to_json(options = nil) ⇒ Object

:nodoc:



2
3
4
# File 'lib/active_support/json/encoders/string.rb', line 2

def to_json(options = nil) #:nodoc:
  ActiveSupport::JSON::Encoding.escape(self)
end

#to_xsObject

XML escaped version of to_s



110
111
112
113
114
# File 'lib/active_support/vendor/builder-2.1.2/builder/xchar.rb', line 110

def to_xs
  unpack('U*').map {|n| n.xchr}.join # ASCII, UTF-8
rescue
  unpack('C*').map {|n| n.xchr}.join # ISO-8859-1, WIN-1252
end