Hi Arup,

Sorry if I misunderstood your question, but I'll try to help.

"12\^ abc23 44".scan(/\d+/) { |e| e  }
# It iterates through each element and then returns the 'source' String!

So if you run the line you have pasted, you just receive back the
string you've given.
But it truly has iterated through all matches.
To see it, change

"12\^ abc23 44".scan(/\d+/) { |e| e  }
to
"12\^ abc23 44".scan(/\d+/) { |e| puts e  }

And you're gonna see it outputting:
12
23
44
# And then returns => "12^ abc23 44"

If you use map (alias for collect) it collects/maps those values.

So,

"12\^ abc23 44".scan(/\d+/)
"12\^ abc23 44".scan(/\d+/).map { |e| e }



Was it related to your question? Did it help you?

On Sun, Jul 6, 2014 at 2:55 AM, Arup Rakshit <aruprakshit / rocketmail.com> wrote:
> On Sunday, July 06, 2014 12:14:37 PM Arup Rakshit wrote:
>> On Saturday, July 05, 2014 09:37:00 PM Robert Klemme wrote:
>> > On Sat, Jul 5, 2014 at 2:38 PM, Arup Rakshit <aruprakshit / rocketmail.com>
>
>> I want to know in the below code :-
>>
>> "12\^ abc23 44".enum_for(:scan, /\d+/).with_object([]) { |e, a| a << e.to_i
>> } #or
>> "12\^ abc23 44".enum_for(:scan, /\d+/).map { |e, a| a << e.to_i }
>>
>
> sorry for wrong copy paste :-
>
>  "12\^ abc23 44".enum_for(:scan, /\d+/).map { |e| e.to_i }
>
> --
> ================
> Regards,
> Arup Rakshit
> ================
> Debugging is twice as hard as writing the code in the first place. Therefore,
> if you write the code as cleverly as possible, you are, by definition, not
> smart enough to debug it.
>
> --Brian Kernighan