What is the keyword to replace an object in 'Ruby'? As in Python it's "replace". | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the keyword to replace an object in 'Ruby'? As in Python it's "replace".

7th Nov 2020, 9:43 AM
Dhiraj Dubey
Dhiraj Dubey - avatar
2 Answers
+ 7
puts("aaa".gsub("a","b")) #bbb
7th Nov 2020, 9:59 AM
TOLUENE
TOLUENE - avatar
+ 5
"nine zero zero".gsub("zero","nine") #nine nine nine "nine zero zero".sub("zero","nine") #nine nine zero #replaces only first occuring String
7th Nov 2020, 11:50 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar