patternrubyMinor
Ruby if-statement, possible to shorten it further?
Viewed 0 times
statementfurthershortenpossibleruby
Problem
Is it possible to shorten this, or to improve the code in any way? I know it's just a simple if-statement, but it's always fun to learn a shorter way of doing things.
if self.citizenship == 'ES'
@identification_type = IDENTIFICATION_TYPES[0]
elsif self.country == 'ES'
@identification_type = IDENTIFICATION_TYPES[1]
endSolution
You could remove a little duplication like this:
@identification_type = if self.citizenship == 'ES'
IDENTIFICATION_TYPES[0]
elsif self.country == 'ES'
IDENTIFICATION_TYPES[1]
endCode Snippets
@identification_type = if self.citizenship == 'ES'
IDENTIFICATION_TYPES[0]
elsif self.country == 'ES'
IDENTIFICATION_TYPES[1]
endContext
StackExchange Code Review Q#7252, answer score: 3
Revisions (0)
No revisions yet.