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


Groups > comp.lang.ruby > #7177

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

Newsgroups comp.lang.ruby
Date 2015-12-23 11:02 -0800
References <5fc33a05-0c6f-4082-a815-3dc044b13cff@googlegroups.com> <ddu37fFlkt1U1@mid.individual.net> <b368625d-aa48-44e2-a0bf-642e0975223f@googlegroups.com> <ddvag6Fug3jU1@mid.individual.net> <7c9b5796-0698-40e1-85cf-77c5f916b8b1@googlegroups.com>
Message-ID <a7a59ebe-d4fe-4695-ad76-803035759236@googlegroups.com> (permalink)
Subject Re: getting in between results of chunks of ruby code, by how???
From artbot <am@artbot.de>

Show all headers | View raw


On Wednesday, December 23, 2015 at 2:49:33 PM UTC+1, artbot wrote:
> On Wednesday, December 23, 2015 at 11:14:38 AM UTC+1, Robert Klemme wrote:
> > On 23.12.2015 10:37, artbot wrote:
> > 
> > > it's going to be part of my (very specialized) template engine.
> > 
> > And what makes it special?  What are your requirements etc.?
> > 
> > > it should be as code/ruby agnostic as possible. evaluating each block
> > > should just recognize if it produces a result or not. also repetitions
> > > should get recognized (as above)
> > 
> > You cannot recognize that and be Ruby agnostic at the same time.  Just 
> > look at your example: you have a block there as second array element 
> > which is invoked an unknown number of times by the first chunk.  So you 
> > would somehow have to tap into the callback from #times and store all 
> > evaluation results of the block's body etc.  No way this flies by only 
> > being mildly Ruby agnostic.
> > 
> > > any more ideas?
> > 
> > You provide the requirements, others can come up with ideas.
> > 
> > Regards
> > 
> > 	robert
> > 
> > 
> > -- 
> > remember.guy do |as, often| as.you_can - without end
> > http://blog.rubybestpractices.com/
> 
> my requirements boil down to what i've described in my first post.
> i thought it can be solved with some metaprogramming magic, maybe someone can
> give me some more (meta or even better: real code) hints how to proceed ...

for now i have introduce a new symbol '<-' in my ruby chunks, using
this i will try to proceed tho following path:

arr= [ "a= 4\na.times do |i|", "  c=i*i\n  <-c","end","<-a"]


arr.each_with_index do |a,i|
  arr[i]= a.gsub(/^\s*<-/,"yield #{i},")
end

str= "def iterator\n" + arr.join("\n") + "\nend"
print "str:\n", str

eval(str)

iterator do |*e|
  print "\ne= ", e
end

what do you think?

cheers 

artur

Back to comp.lang.ruby | Previous | NextPrevious 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