Assign greater of two ints?

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

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

  • donald

Ball, Donald A Jr (Library) wrote:

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

  • donald

Excellent. Thanks.

Earle

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs