Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#next(str) ⇒ String

Places a string to the right of the current string

Example:

ab        ef      abef
cd .next( gh ) => cdgh

Parameters:

  • str (String)

    The string to place adjacent

Returns:

  • (String)

    The constructed string



10
11
12
13
14
15
16
17
# File 'lib/extensions/string.rb', line 10

def next(str)
  # zip the two strings, split by line breaks
  zipped = self.split("\n").zip(str.split("\n"))

  # map the zipped strings, by joining each pair and ending
  #   with a new line, then joining the whole thing together
  zipped.map { |e| "#{e.join}" }.join "\n"
end