Mapping an object

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

···

--
Posted via http://www.ruby-forum.com/.

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

···

On 10/4/07, Harnish Botadra <harnish_544@yahoo.com> 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.

Quoth Harnish Botadra:

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

result = A.get_arr.first # => First object of A.get_arr's array.

···

--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertillnoon.com/