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