Mapping an object

  • Thread starter Harnish Botadra
  • Start date
H

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
 
H

Harold Hausman

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
 
K

Konrad Meyer

--nextPart2064973.nv492St4da
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Quoth Harnish Botadra:
Hi,
=20
This is Harnish. I am looking for a way to map an object.
=20
Ex:
=20
Instead of doing,
=20
resultset =3D A.get_arr
result =3D resultset[0].my_obj
=20
=20
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.
=20
Thanks for your help.
=20
Regards,
Harnish

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

=2D-=20
Konrad Meyer <[email protected]> http://konrad.sobertillnoon.com/

--nextPart2064973.nv492St4da
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBHBY4ICHB0oCiR2cwRAlNdAKDFcQBvyyszts3RGszzOAUqv1wfNwCcCRX3
997FoveAApCRf6cADcTK7UA=
=Ie66
-----END PGP SIGNATURE-----

--nextPart2064973.nv492St4da--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,268
Messages
2,571,344
Members
48,019
Latest member
Migration_Expert

Latest Threads

Top