Sha256: 083ca3c090932a3ac67a1a45da071634eb1305d2c97900d8a61c742aeb6aa0a2

Contents?: true

Size: 781 Bytes

Versions: 26

Compression:

Stored size: 781 Bytes

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

# encoding=utf-8

module StringUtil
  # 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.
  #
  # @param input_str [String] The string to be split.
  # @param split_char [String] The character on which to split the string.
  # @return [Array<String>] An array containing two elements: the part of the string before split_char, and the rest of the string.
  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
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
markdown_exec-2.1.0 lib/string_util.rb
markdown_exec-2.0.8.4 lib/string_util.rb
markdown_exec-2.0.8.3 lib/string_util.rb
markdown_exec-2.0.8.2 lib/string_util.rb
markdown_exec-2.0.8.1 lib/string_util.rb
markdown_exec-2.0.8 lib/string_util.rb
markdown_exec-2.0.7 lib/string_util.rb
markdown_exec-2.0.6 lib/string_util.rb
markdown_exec-2.0.5 lib/string_util.rb
markdown_exec-2.0.4 lib/string_util.rb
markdown_exec-2.0.3.2 lib/string_util.rb
markdown_exec-2.0.3.1 lib/string_util.rb
markdown_exec-2.0.3 lib/string_util.rb
markdown_exec-2.0.2 lib/string_util.rb
markdown_exec-2.0.1 lib/string_util.rb
markdown_exec-2.0.0 lib/string_util.rb
markdown_exec-1.8.9 lib/string_util.rb
markdown_exec-1.8.8 lib/string_util.rb
markdown_exec-1.8.7 lib/string_util.rb
markdown_exec-1.8.6 lib/string_util.rb