0

I am fairly new to Ruby and was wondering if there is a way to extract unique struct values within an array.

I have the following struct:

Struct.new(:source_ip_address, :destination_ip_address, :port)

Within my code I am getting these struct values from a file, then storing them in an array:

ip_port_list

So basically for each line in the file, a new struct is created. That struct is then added to the ip_port_list array. The next thing I am trying to do is pull out all the unique port values within the entire array. Is there a way to do this? Any help would be greatly appreciated.

1 Answer 1

5
ip_port_list.map(&:port).uniq

Should do it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.