# Mapping an object

**URL:** <https://www.ruby-forum.com/t/mapping-an-object/116383>\
**Category:** Ruby\
**Created:** [October 5, 2007, 2:17am UTC](https://www.ruby-forum.com/t/mapping-an-object/116383 "2007-10-05T02:17:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbotadra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hbotadra](https://www.ruby-forum.com/u/hbotadra)\
**Post date:** [October 5, 2007, 2:17am UTC](https://www.ruby-forum.com/t/mapping-an-object/116383/1 "2007-10-05T02:17:53Z")

</div>

Hi,

This is Harnish. I am looking for a way to map an object.

Ex:

Instead of doing,

resultset = A.get\_arr  
result = resultset[0].my\_obj

Can I combine the 2 statements into 1 when I know that my A.get\_arr is  
sure to return an array with just 1 object.

Thanks for your help.

Regards,  
Harnish

---

<div class="post-metadata">

**Author:** ![hbotadra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hbotadra](https://www.ruby-forum.com/u/hbotadra)\
**Post date:** [October 5, 2007, 2:28am UTC](https://www.ruby-forum.com/t/mapping-an-object/116383/2 "2007-10-05T02:28:15Z")

</div>

On 10/4/07, Harnish B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Instead of doing,
> 
> resultset = A.get\_arr  
> result = resultset[0].my\_obj
> 
> Can I combine the 2 statements into 1 when I know that my A.get\_arr is  
> sure to return an array with just 1 object.

I think your code could just become:  
result = A.get\_arr[0].my\_obj

Consider this:  
irb(main):002:0\> def foo; [“foo”]; end  
=\> nil  
irb(main):003:0\> foo[0].reverse  
=\> “oof”

Hope that helps,  
-Harold

---

<div class="post-metadata">

**Author:** ![hbotadra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hbotadra](https://www.ruby-forum.com/u/hbotadra)\
**Post date:** [October 5, 2007, 3:07am UTC](https://www.ruby-forum.com/t/mapping-an-object/116383/3 "2007-10-05T03:07:58Z")

</div>

Quoth Harnish B.:

> Can I combine the 2 statements into 1 when I know that my A.get\_arr is  
> sure to return an array with just 1 object.
> 
> Thanks for your help.
> 
> Regards,  
> Harnish

result = A.get\_arr.first # =\> First object of A.get\_arr’s array.
