3 ms·
Sure, I'm always nervous about showing off my sloppy code but here it is. http://pastie.caboo.se/161944 http://pastie.caboo.se/161944 It's not the craziest co
by Readmore 19y ago
Sure, I'm always nervous about showing off my sloppy code but here it is.
http://pastie.caboo.se/161944 http://pastie.caboo.se/161944
It's not the craziest code ever but it allows me to store site specific indexing code in a file and then load the correct code based on the site being indexed.
- iamwil 19y agoI've been using Ruby for a while, but I've been using proc/lamba and eval sparingly. It's nice when you need it. I've mostly used proc to delay computation by passing blocks around, and eval to generate code or class_eval to write as if I was writing in the class. Anyone else use them for anything else? So, the aha moment was being able to use eval as an interpreter, and lambda to enclose it to pass it around?
- bct 19y agoAny reason you did parseClosure(x,y,lambda {|doc,out| ... }) instead of parseClosure(x,y) { |doc,out| ... } ?
- Readmore 19y agoI tried to pass the codeProc.call in the block but it wouldn't process the data until I passed the codeProc as a parameter. I don't really understand why to be honest.
- bct 19y agoI don't know why it wouldn't have. You should have been able to do: out = parseClosure(curr_page, cnt) { |doc,out| eval(codeStr) } ... def parseClosure(curr_page, cnt) ... yield(doc, out) or: def parseClosure(curr_page, cnt, &codeProc) There's not much opportunity to use lambda explicity in Ruby because using blocks instead is so easy.
- Readmore 19y agoYou are correct sir! I bow to your ruby-fu! Thanks.