

Ah-Ha Moment: I wrote my first program with eval and lambda! - Readmore

I've 'understood' what eval and lambda were for in Ruby but I hadn't ever had a real reason to use it for anything, until today.<p>Now I REALLY get what they are for and I can definitely see how you could use them all over the place.<p>Just wanted to share my Hacker Joy ;)
======
jdvolz
I feel the same way about Ruby and Javascript. I can't imagine what I was
doing where I could have been using "eval" in C#. I was having to write my own
interpreters inside the program and then pass around strings, which is crappy.

------
nonrecursive
Can you share the code?

~~~
Readmore
Sure, I'm always nervous about showing off my sloppy code but here it is.

<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.

~~~
bct
Any reason you did parseClosure(x,y,lambda {|doc,out| ... }) instead of
parseClosure(x,y) { |doc,out| ... } ?

~~~
Readmore
I 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
I 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
You are correct sir! I bow to your ruby-fu!

Thanks.

