@string = "Sometimes some stupid people say some stupid words"
@string.enclose_in_brackets("some") # => "Sometimes {some} stupid people say {some} stupid words"
How should the method enclose_in_brackets look ? Please keep in mind, I want only enclose whole words, (I don’t want “{Some}times {some} stupid….”, the “sometimes” word should be left unchanged
It’s just a string substitution using a regular expression. You can use the word boundary special character to prevent it from matching your parameter when it’s in the middle of another word. And put your method inside the
Stringclass so that you can call it directly on a string like in your example.