Q:

Ruby, how to change every "s" in each word of string, except if "s" is first letter

Trying to create a simple multi-word string method that replaces some of the letters of a string (3 for "e", 0 for "o", 1 for "I", and "z" for "s" (unless "s" is first letter in word. So, "sons sams roses" will change to "sonz samz roz3z".
All of my specs pass except for not changing the first 's' of each word in a string. I can't seem to go from working with each letter in a string to each word, targeting the first letter.
class String
  def leetspeak
    word = self.split("")
    new_word = []

    word.each do |i|
      if i == "e"
        new_word.push(3)
      elsif i == "o"
        new_word.push(0)
      elsif i == "I"
        new_word.push(1)
      elsif (i == "s") && ((word.find_index(" ") + 1) != "s")
        new_word.push("z")
      else
        new_word.push(i)
      end
    end
    new_word.join
  end
end

On the last elsif, I thought I could target the first letter using .find_index(" ") + 1, but it doesn't work, and even if it did, it doesn't work for the very first letter in the string, if it was "s". Any help would be appreciated. 

A:

There's many ways to accomplish that. Do you require this implementation to be using if/else? Otherwise, here follows a simpler one:
def leetspeak
  self
    .gsub('e', '3')
    .gsub('o', '0')
    .gsub('I', '1')
    .gsub(/(?!^)s/, 'z')
end

The /(?!^)s/ part is a Regular Expression (or regex) that means everything that's an s except if it's the first character. The (?!something) is the negative lookahead, and the ^ is the beginning of the string. The gsub method replaces globally (in the whole string) any substring which is matched by the expression, and replaces it with the second argument.
I'm sure that are better ways to do that, both in performance and in clarity, but I guess this implementation should be good enough.
UPDATE:
I had misread the question, I've fixed the regex to not match every first s in any word using the \b, which stands for word boundary.
def leetspeak
  self
    .gsub('e', '3')
    .gsub('o', '0')
    .gsub('I', '1')
    .gsub(/(?!\b)s/, 'z')
end

