123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::SafeBuffer

Relationships & Source Files
Namespace Children
Exceptions:
Extension / Inclusion / Inheritance Descendants
Subclasses:
ActionView::OutputBuffer
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::String
Instance Chain:
self, ::String
Inherits: String
Defined in: activesupport/lib/active_support/core_ext/string/output_safety.rb

Constant Summary

::String - Inherited

BLANK_RE

Class Method Summary

Instance Attribute Summary

::String - Inherited

#acts_like_string?

Enable more predictable duck-typing on String-like classes.

#blank?

A string is blank if it's empty or contains whitespaces only:

#is_utf8?

Instance Method Summary

::String - Inherited

#at

If you pass a single integer, returns a substring of one character at that position.

#camelcase

Alias for String#camelize.

#camelize

By default, camelize converts strings to UpperCamelCase.

#classify

Create a class name from a plural table name like ::Rails does for table names to models.

#constantize

constantize tries to find a declared constant with the name specified in the string.

#dasherize

Replaces underscores with dashes in the string.

#deconstantize

Removes the rightmost segment from the constant expression in the string.

#demodulize

Removes the module part from the constant expression in the string.

#ends_with?,
#exclude?

The inverse of String#include?.

#first

Returns the first character.

#foreign_key

Creates a foreign key name from a class name.

#from

Returns a substring from the given position to the end of the string.

#html_safe

Marks a string as trusted safe.

#humanize

Capitalizes the first word, turns underscores into spaces, and strips a trailing '_id' if present.

#in_time_zone

Converts String to a TimeWithZone in the current zone if Time.zone or Time.zone_default is set, otherwise converts ::String to a ::Time via String#to_time

#indent

Indents the lines in the receiver:

#indent!

Same as indent, except it indents the receiver in-place.

#inquiry

Wraps the current string in the StringInquirer class, which gives you a prettier way to test for equality.

#last

Returns the last character of the string.

#mb_chars

Multibyte proxy.

#parameterize

Replaces special characters in a string so that it may be used as part of a 'pretty' URL.

#pluralize

Returns the plural form of the word in the string.

#remove

Returns a new string with all occurrences of the patterns removed.

#remove!

Alters the string by removing all occurrences of the patterns.

#safe_constantize

safe_constantize tries to find a declared constant with the name specified in the string.

#singularize

The reverse of pluralize, returns the singular form of a word in a string.

#squish

Returns the string, first removing all whitespace on both ends of the string, and then changing remaining consecutive whitespace groups into one space each.

#squish!

Performs a destructive squish.

#starts_with?,
#strip_heredoc

Strips indentation in heredocs.

#tableize

Creates the name of a table like ::Rails does for models to table names.

#titlecase

Alias for String#titleize.

#titleize

Capitalizes all the words and replaces some characters in the string to create a nicer looking title.

#to

Returns a substring from the beginning of the string to the given position.

#to_date

Converts a string to a ::Date value.

#to_datetime

Converts a string to a ::DateTime value.

#to_time

Converts a string to a ::Time value.

#truncate

Truncates a given text after a given length if text is longer than length:

#truncate_words

Truncates a given text after a given number of words (words_count):

#underscore

The reverse of camelize.

Constructor Details

.newSafeBuffer

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 170

def initialize(*)
  @html_safe = true
  super
end

Instance Attribute Details

#html_safe?Boolean (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 213

def html_safe?
  defined?(@html_safe) && @html_safe
end

Instance Method Details

#%(args)

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 202

def %(args)
  case args
  when Hash
    escaped_args = Hash[args.map { |k,arg| [k, html_escape_interpolated_argument(arg)] }]
  else
    escaped_args = Array(args).map { |arg| html_escape_interpolated_argument(arg) }
  end

  self.class.new(super(escaped_args))
end

#+(other)

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 198

def +(other)
  dup.concat(other)
end

#<<(value)

Alias for #concat.

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 187

alias << concat

#[](*args)

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 147

def [](*args)
  if args.size < 2
    super
  else
    if html_safe?
      new_safe_buffer = super

      if new_safe_buffer
        new_safe_buffer.instance_variable_set :@html_safe, true
      end

      new_safe_buffer
    else
      to_str[*args]
    end
  end
end

#clone_empty

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 180

def clone_empty
  self[0, 0]
end

#concat(value) Also known as: #<<

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 184

def concat(value)
  super(html_escape_interpolated_argument(value))
end

#encode_with(coder)

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 225

def encode_with(coder)
  coder.represent_object nil, to_str
end

#initialize_copy(other)

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 175

def initialize_copy(other)
  super
  @html_safe = other.html_safe?
end

#prepend(value)

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 189

def prepend(value)
  super(html_escape_interpolated_argument(value))
end

#prepend!(value)

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 193

def prepend!(value)
  ActiveSupport::Deprecation.deprecation_warning "ActiveSupport::SafeBuffer#prepend!", :prepend
  prepend value
end

#safe_concat(value)

Raises:

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 165

def safe_concat(value)
  raise SafeConcatError unless html_safe?
  original_concat(value)
end

#to_param

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 221

def to_param
  to_str
end

#to_s

[ GitHub ]

  
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 217

def to_s
  self
end