Posts

Showing posts with the label usage of gsub in ror

Ruby's Gsub method usage

Hi, This is  Shubham Mishra  a ROR, iOS, Python developer,  this is the part of  Ruby on Rails  exploration journey.  In this post we will discuss about the Awesome ways to use ruby's Gsub method. Now, lets first understand the term 'gsub' -> 'sub': Substitute,  'g': global Sounds a little odd, no problem lets go practically for better understanding. Lets say we have a string,  str = "Awesome season" What we want is to replace a word with another in ruby, say in our case it is replacing season with movie, now what we will do is, This is saying : Replace all the occurrences of the first word 'season' with the 'movie' Well other than just replacement task your gsub method can do a lot more stuffs, let's have a watch. Replace pattern with regular expression : So now lets learn to replace not only a single word but a sentences matching a regular expression, such as matching a phone number, email address etc The first option is ...