Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7172

getting in between results of chunks of ruby code, by how???

Newsgroups comp.lang.ruby
Date 2015-12-22 12:13 -0800
Message-ID <5fc33a05-0c6f-4082-a815-3dc044b13cff@googlegroups.com> (permalink)
Subject getting in between results of chunks of ruby code, by how???
From artbot <am@artbot.de>

Show all headers | View raw


hi all,

i've a problem with evaluating ruby chunks in an array. the setting is as follows (and may seem exotic, but anyway):

let start with an array 'arr'

arr= ["a= rand(4)+2\na.times do |i|","c= i*i\nc","end","b=a*a\nb"]

the array 'arr' contains a valid ruby program, which can be run using:

eval(arr.join)

so far so easy. but i need to get the evaluation of the in between steps also as subresults.

starting with the above array 'arr', i'd like to get (for 'a' being 3)

brr= [nil, [0, 1, 4], nil, 9]

so each ruby code chunk should store it's last value (can be nil)
at the same array index as the original ruby chunk.

so e.g. as

"a= rand(4)+2\na.times do |i|"

doesn't have a last value, therefore brr[0] is nil.

"c= i*i\nc" is called 3 times, therefore brr[1] is
an array of size 3 with the corresponding results

"end" doesn't have a value, therefore brr[2] is nil

brr[3] is 9, as 3*3 is 9

any idea how this can be done with eval or something else in ruby???

thanx

artur

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar


Thread

getting in between results of chunks of ruby code, by how??? artbot <am@artbot.de> - 2015-12-22 12:13 -0800
  Re: getting in between results of chunks of ruby code, by how??? Robert Klemme <shortcutter@googlemail.com> - 2015-12-23 00:04 +0100
    Re: getting in between results of chunks of ruby code, by how??? artbot <am@artbot.de> - 2015-12-23 01:37 -0800
      Re: getting in between results of chunks of ruby code, by how??? Robert Klemme <shortcutter@googlemail.com> - 2015-12-23 11:14 +0100
        Re: getting in between results of chunks of ruby code, by how??? artbot <am@artbot.de> - 2015-12-23 05:49 -0800
          Re: getting in between results of chunks of ruby code, by how??? artbot <am@artbot.de> - 2015-12-23 11:02 -0800

csiph-web