Sha256: 12d57abd98d8c702113d580ce25d8c72eb414814e7e127d1bf30acf99ef2364b
Contents?: true
Size: 780 Bytes
Versions: 8
Compression:
Stored size: 780 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
8 entries across 8 versions & 1 rubygems