Ruby Build an Address Book in Ruby Search Searching by Phone Number

MICHAEL P
MICHAEL P
5,190 Points

What is the reason to use the gsub method? I am not quite clear on the use of it.

What is the reason to use the gsub method? I am not quite clear on the use of it.

2 Answers

rowend rowend
rowend rowend
2,923 Points

It replaces all the charcaters '-' with empty strings. For example: '1-2-3' becomes '123'.

Marcus Quarles
Marcus Quarles
14,598 Points

Hello,

In order to gain a better understanding of the .gsub method you should review the regular expressions concept as a whole. http://www.dotnetperls.com/sub-ruby has nice examples that show what the method does.