[LRUG] Subtracting two arrays

John Winters john at sinodun.org.uk
Thu Dec 16 10:23:38 PST 2010


A quick technical question if I may.

I'm still learning Ruby and have come across something which I feel sure 
the standard libraries should be able to do, but I can't find an 
existing way to do it.

I have two arrays, one of which lists all the rooms in a school and the 
other of which lists all the rooms currently in use.  I want to print a 
list of free rooms, so essentially I need a new array consisting of all 
the elements of the first array which aren't in the second array.

Obviously I can hand-craft a suitable function quite easily, but I'm 
getting used to being able to do all these sort of things with a simple 
Ruby one-liner.  Does such a way exist?

TIA,
John



More information about the Chat mailing list