Ruby - String Operations
What is the output of the following Ruby code?
text = "foo bar foo bar"
result = text.sub('foo', 'baz')
puts resulttext = "foo bar foo bar"
result = text.sub('foo', 'baz')
puts resultsub replaces only the first occurrence of 'foo' with 'baz'.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions