Assign greater of two ints?


#1

Is there a more concise way to write this?

a = 5
b = “test123”
if a < b.length
a = b.length
end

–or–

a = b.length if a < b.length

Earle


#2

a = b.length if a < b.length
a = [a, b.length].max

  • donald

#3

Ball, Donald A Jr (Library) wrote:

a = b.length if a < b.length
a = [a, b.length].max

  • donald

Excellent. Thanks.

Earle