mr_muscle
mr_muscle

Reputation: 2900

Ruby difference in two string arrays and pass to the method

I've got following array of strings with nicknames of owners:

OWNERS = %w[test1 test2 test3].freeze

I want to detect any differences in the list of owners (e.g. when new user was granted owner role). To do so I'm getting list of current_owners which represents array of strings:

current_owners = %w[test1 test2 test3]

How to fetch changes when current_owners will be not the same as OWNERS and pass this difference to another method?

Example:

OWNERS = %w[test1 test2 test3].freeze
current_owners = %w[test1 test2 test3 newuser test10]

I want to pass 'newuser' and test10 as a parameter to the method new_owner_alarm(string) to be like new_owner_alarm('newuser'), new_owner_alarm('test10')

Upvotes: 0

Views: 36

Answers (1)

ndnenkov
ndnenkov

Reputation: 36101

(current_owners - OWNERS).each { |new_owner| new_owner_alarm(new_owner) }

Upvotes: 1

Related Questions