Xitcod13
Xitcod13

Reputation: 6079

checking if all values of a hash are correct values (from a predefined value set) in ruby

I have a hash table with multiple values being passed to a function I dont know the names of the keys but i know that the values of the keys must be equal to characters A S or X. How can i easily check that all values in the hash table are equal to those characters?

Upvotes: 0

Views: 92

Answers (1)

oldergod
oldergod

Reputation: 15010

NullUserException is good, you could also

match_values = %w(A S X)
hash.values.all? { |value| match_values.include?(value) }

Upvotes: 2

Related Questions