capture code in a block - RUBY

This is a discussion on capture code in a block - RUBY ; Greetings, How might I capture the code in a block so that I can serialize it for later use? So for example ... file = CodeFile.new( 'something.rb') file.capture do puts 'Hello World' end .... which prompts a file to be ...

+ Reply to Thread
Results 1 to 3 of 3

capture code in a block

  1. Default capture code in a block

    Greetings,

    How might I capture the code in a block so that I can serialize it for
    later use? So for example ...

    file = CodeFile.new( 'something.rb')

    file.capture do
    puts 'Hello World'
    end

    .... which prompts a file to be created with ...

    puts 'Hello World'

    Any thoughts how this might be accomplished?

    ]{


  2. Default Re: capture code in a block

    --nextPart2175644.v5JOTTBBfD
    Content-Type: text/plain;
    charset="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: inline

    Quoth Kristoph:
    > Greetings,
    >=20
    > How might I capture the code in a block so that I can serialize it for
    > later use? So for example ...
    >=20
    > file =3D CodeFile.new( 'something.rb')
    >=20
    > file.capture do
    > puts 'Hello World'
    > end
    >=20
    > ... which prompts a file to be created with ...
    >=20
    > puts 'Hello World'
    >=20
    > Any thoughts how this might be accomplished?


    Do you actually want a literal "puts 'Hello World'" in the file, or just th=
    e=20
    string "Hello World"?

    def my_method &block
    @block =3D block
    end

    def my_other_method
    @block.call
    end

    Something like that?

    HTH,
    =2D-=20
    Konrad Meyer <konrad@tylerc.org> http://konrad.sobertillnoon.com/

    --nextPart2175644.v5JOTTBBfD
    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)

    iD8DBQBHGU/+CHB0oCiR2cwRAtv6AJ0fEwmouk6VwJtzqXA+Xf5p34gg2QCePSev
    7cyCXm2/+L7vbmxmivYoFfk=
    =L7UK
    -----END PGP SIGNATURE-----

    --nextPart2175644.v5JOTTBBfD--


  3. Default Re: capture code in a block

    Konrad,

    Yes I want to capture and serialize the actual code into a file (and
    not actually execute that code until some later juncture).

    Basically I just want the contents of a block as a string, without
    executing it.

    Kristoph

    On Oct 19, 5:46 pm, Konrad Meyer <kon...@tylerc.org> wrote:
    > Quoth Kristoph:
    >
    >
    >
    > > Greetings,

    >
    > > How might I capture the code in a block so that I can serialize it for
    > > later use? So for example ...

    >
    > > file = CodeFile.new( 'something.rb')

    >
    > > file.capture do
    > > puts 'Hello World'
    > > end

    >
    > > ... which prompts a file to be created with ...

    >
    > > puts 'Hello World'

    >
    > > Any thoughts how this might be accomplished?

    >
    > Do you actually want a literal "puts 'Hello World'" in the file, or just the
    > string "Hello World"?
    >
    > def my_method &block
    > @block = block
    > end
    >
    > def my_other_method
    > @block.call
    > end
    >
    > Something like that?
    >
    > HTH,
    > --
    > Konrad Meyer <kon...@tylerc.org>http://konrad.sobertillnoon.com/
    >
    > signature.asc
    > 1KDownload




+ Reply to Thread

Similar Threads

  1. .max a Block of code with yield?
    By Application Development in forum RUBY
    Replies: 2
    Last Post: 12-08-2007, 04:59 PM
  2. How to going to a code block/line?
    By Application Development in forum c++
    Replies: 6
    Last Post: 11-26-2007, 04:51 AM
  3. Re: Run block of code periodically
    By Application Development in forum labview
    Replies: 0
    Last Post: 10-21-2007, 11:40 AM
  4. Code Block Safety
    By Application Development in forum Clipper
    Replies: 1
    Last Post: 02-14-2006, 12:12 PM
  5. Two Questions about the Following Block of Code
    By Application Development in forum Javascript
    Replies: 2
    Last Post: 10-09-2003, 12:31 PM