I don't know Ruby, so I'm not sure this is at all idiomatic. However, you can do something like this (if you're looking for a one-liner):
@identification_type = IDENT_TYPES[[@citizenship, @country].index('ES')]
Just so this makes some sort of sense (in case I didn't understand your code), here is some context:
IDENT_TYPES = {0 => :citizen, 1 => :country}
class Foo
attr_accessor = :citizenship, :country, :identification_type
def initialize(citizenship, country)
@citizenship = citizenship
@country = country
@identification_type = IDENT_TYPES[[@citizenship, @country].index('ES')]
puts @identification_type
end
end
foo = Foo.new('ES', 'EN')
foo = Foo.new('EN', 'ES')
foo = Foo.new('EN', 'EN')
This outputs:
citizen
country
nil