ruby on rails - Getting data out of MatchData got as a result from match function -
i have array of custom objects in it. objects have parameter called name concatenation of 2 strings having delimiter in between. eg: name some@data 'some' first string , 'data' , @ delimiter.
my intention update name parameter objects inside array such param have 'data' (i.e. remove 'some@') , store objects inside array after updating. below code:
final_array = array1.select |object| object.name = object.name.match(/@(.*?)$/) end
when print object.name.match(/@(.*?)$/)
gives me output as:
#<matchdata "@data" 1:"data">
out of output, how "data" matchdata. tried object.name.match(/@(.*?)$/)[1]
didn't work. or need change regex?
i use #each , #gsub methods:
array.each |object| object.name = object.name.gsub(/^.+@/, '') end
Comments
Post a Comment