Forum: Ruby assign greater of two ints?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F50f406e6c261349179ead121e6c9a0f?d=identicon&s=25 Earle Clubb (eclubb)
on 2007-06-22 21:20
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
E1f43bafda26307a050d11902752b2a6?d=identicon&s=25 Ball, Donald A Jr (Library) (Guest)
on 2007-06-22 21:26
(Received via mailing list)
> a = b.length if a < b.length
a = [a, b.length].max

- donald
F50f406e6c261349179ead121e6c9a0f?d=identicon&s=25 Earle Clubb (eclubb)
on 2007-06-22 22:15
Ball, Donald A Jr (Library) wrote:
>> a = b.length if a < b.length
> a = [a, b.length].max
>
> - donald

Excellent.  Thanks.

Earle
This topic is locked and can not be replied to.