Get uniq objects from data in Ruby

Some times we need uniq objects while performing complex operations
and avoid duplicate..

def make_uniq_by(&blk)
	object_set = []
	self.select do |el|
		only_uniq_objects = !object_set.include?(data=blk[el])
		object_set << data
		only_uniq_objects
	end
end

Thanks …. Feedback and suggestion are welcome..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s