Sha256: 60e8eece3b238297a6914fb4b39b3656b01a12fb314dc489f76f173d0ae9bc4b

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

class String {
  """
  Strings are sequences of characters and behave as such.
  All literal Strings within Fancy code are instances of the String
  class.

  They also include FancyEnumerable, which means you can use all the
  common sequence methods on them, like +map:+, +select:+ etc.
  """

  include: FancyEnumerable

  def ++ other {
    "Concatenate the String with another String"

    self + (other to_s)
  }

  def whitespace? {
    "Indicates, if a String is empty or a single whitespace character."

    empty? or: (self == " ")
  }

  def blank? {
    "Indicates, if a String consists only of whitespace."

    self =~ /^\s*$/ if_true: {
      true
    } else: {
      false
    }
  }

  def * num {
    "Returns a string that is the num-fold concatenation of itself."

    str = ""
    num to_i times: {
      str = str ++ self
    }
    str
  }

  def words {
    split
  }

  def raise! {
    "Raises a new StdError with self as the message."
    StdError new: self . raise!
  }

  def rest {
    "Returns a @String@ containing all but the first character."
    from: 1 to: -1
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fancy-0.3.3 lib/string.fy