# Assign greater of two ints?

**URL:** <https://www.ruby-forum.com/t/assign-greater-of-two-ints/107544>\
**Category:** Ruby\
**Created:** [June 22, 2007, 9:20pm UTC](https://www.ruby-forum.com/t/assign-greater-of-two-ints/107544 "2007-06-22T21:20:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eclubb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecc23a/32.png) [@eclubb](https://www.ruby-forum.com/u/eclubb)\
**Post date:** [June 22, 2007, 9:20pm UTC](https://www.ruby-forum.com/t/assign-greater-of-two-ints/107544/1 "2007-06-22T21:20:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eclubb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecc23a/32.png) [@eclubb](https://www.ruby-forum.com/u/eclubb)\
**Post date:** [June 22, 2007, 9:26pm UTC](https://www.ruby-forum.com/t/assign-greater-of-two-ints/107544/2 "2007-06-22T21:26:29Z")

</div>

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

- donald

---

<div class="post-metadata">

**Author:** ![eclubb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecc23a/32.png) [@eclubb](https://www.ruby-forum.com/u/eclubb)\
**Post date:** [June 22, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/assign-greater-of-two-ints/107544/3 "2007-06-22T22:15:45Z")

</div>

Ball, Donald A Jr (Library) wrote:

> > a = b.length if a \< b.length  
> > a = [a, b.length].max
> 
> - donald

Excellent. Thanks.

Earle
