1

My response from an API is coming in like:

[0] = "[Identity[id=95571, type=start, userId=d12345, processId=95567]]" [1] = "[Identity[id=95572, type=start, userId=d67890, processId=95568]]" etc 

Lets call the above arr.

I want to retrieve all the userIds

I have tried:

all_users = arr.collect {|ind| ind[2]} 

But this is obviously incorrect. What am I missing?

Thanks

2
  • 1
    Are you sure your array is in correct format ? Commented Sep 3, 2015 at 16:18
  • it is converted to string before being sent, perhaps there is a ruby way to convert it back to a proper array? Commented Sep 3, 2015 at 18:53

1 Answer 1

1

Your array elements are strings, so can use string methods to extract parts from them, e.g.

arr.map { |e| e.match(/\[id=(/d+),/)[1] } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.