String

From RubySpec

Jump to: navigation, search

A Ruby String is generally considered to be a collection of characters. However in practice it is also frequently used as a collection of bytes, and many IO operations produce output and accept input as String objects even for binary content.

Methods

"=="

-------------------------------------------------------------- String#==
     str == obj   => true or false
------------------------------------------------------------------------
     Equality---If _obj_ is not a +String+, returns +false+. Otherwise,
     returns +true+ if _str_ +<=>+ _obj_ returns zero.

The 1.8.5 C code implements String#== as follows:

  • if str1 == str2 return true
  • if str2 is not a String, but it responds to to_str, return str2.==(str1), otherwise return false
  • otherwise do a straight string comparison

"eql?"

------------------------------------------------------------ String#eql?
     str.eql?(other)   => true or false
------------------------------------------------------------------------
     Two strings are equal if the have the same length and content.

eql? always does a string content comparison between two strings (both must be strings).

Personal tools