N
Neville Burnell
------_=_NextPart_001_01C57ADF.00F25475
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi,
I have an active record collection and I need to 'eval' a string against
each row from the collection. Instead of processing the 'eval' for each
row, I was thinking to 'cache' the eval into a Proc to for reuse, ie:
irb(main):001:0> @a =3D 1
=3D> 1
irb(main):002:0> @b =3D 7
=3D> 7
irb(main):003:0> c =3D %q{ @a + @b }
=3D> " @a + @b "
irb(main):004:0> d =3D Proc.new { eval c }
=3D> #<Proc:0x02ad1240@(irb):4>
irb(main):005:0> d.call
=3D> 8
irb(main):006:0> @a =3D 2
=3D> 2
irb(main):007:0> d.call
=3D> 9
irb(main):008:0>
Is my assumption that eval is relatively expensive, and that a Proc call
is fast correct?
Any suggestions on how to do this better?
Thanks=20
Nev
------_=_NextPart_001_01C57ADF.00F25475--
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi,
I have an active record collection and I need to 'eval' a string against
each row from the collection. Instead of processing the 'eval' for each
row, I was thinking to 'cache' the eval into a Proc to for reuse, ie:
irb(main):001:0> @a =3D 1
=3D> 1
irb(main):002:0> @b =3D 7
=3D> 7
irb(main):003:0> c =3D %q{ @a + @b }
=3D> " @a + @b "
irb(main):004:0> d =3D Proc.new { eval c }
=3D> #<Proc:0x02ad1240@(irb):4>
irb(main):005:0> d.call
=3D> 8
irb(main):006:0> @a =3D 2
=3D> 2
irb(main):007:0> d.call
=3D> 9
irb(main):008:0>
Is my assumption that eval is relatively expensive, and that a Proc call
is fast correct?
Any suggestions on how to do this better?
Thanks=20
Nev
------_=_NextPart_001_01C57ADF.00F25475--