Module: StringUtil

Included in:
MarkdownExec::MarkParse
Defined in:
lib/string_util.rb

Class Method Summary collapse

Class Method Details

.partition_at_first(input_str, split_char) ⇒ Array<String>

Splits the given string on the first occurrence of the specified character. Returns an array containing the portion of the string before the character and the rest of the string.

Parameters:

  • input_str (String)

    The string to be split.

  • split_char (String)

    The character on which to split the string.

Returns:

  • (Array<String>)

    An array containing two elements: the part of the string before split_char, and the rest of the string.



12
13
14
15
16
17
18
19
20
# File 'lib/string_util.rb', line 12

def self.partition_at_first(input_str, split_char)
  split_index = input_str.index(split_char)

  if split_index.nil?
    [input_str, '']
  else
    [input_str[0...split_index], input_str[(split_index + 1)..-1]]
  end
end