tags:

views:

65

answers:

1

I'm using this code:

s = line.match( /ABCD(\d{4})/ ).values_at( 1 )[0] 

To extract numbers from strings like:

ABCD1234
ABCD1235
ABCD1236

etc.

It works, but I wonder what other alternative I have to to this in Ruby?

My code:

ids = [] 
someBigString.lines.each {|line|
   ids << line.match( /ABCD(\d{4})/ ).values_at( 1 )[0] 
}
+2  A: 
a.map {|x| x[/\d+/]}
glenn mcdonald
What's the semantic of `map` how should I understand it? I understand `collect` but I have always had trouble understanding map.
OscarRyz
@Oscar Reyes, Enumerable#map is a synonym for Enumerable#collect
Wayne Conrad