uneval,mtime,hash - Meta programming.

J

John Carter

I often do things that take far too much time.

So I create "make" like scripts that understand dependencies and
targets and when things need to be remade or not.

This saves me heaps and heaps of time.

So I just had the idea that I could pull everything into self
contained ruby if I could tell if a method had changed or not so I
would know whether I had to rerun it or not.

Hence the Questions:

Q1. Is there an "uneval" in ruby. ie. Give it a method name, return the
string that, if eval'd would give the method.

Q2. Is there a "method_hash", which would change if the method had changed.

I suppose I could store the methods as strings, compute an md5sum and then 'eval' the string. Hmm.






John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand
 
A

ara.t.howard

I often do things that take far too much time.

So I create "make" like scripts that understand dependencies and
targets and when things need to be remade or not.

This saves me heaps and heaps of time.

So I just had the idea that I could pull everything into self
contained ruby if I could tell if a method had changed or not so I
would know whether I had to rerun it or not.

Hence the Questions:

Q1. Is there an "uneval" in ruby. ie. Give it a method name, return the
string that, if eval'd would give the method.

Q2. Is there a "method_hash", which would change if the method had changed.

I suppose I could store the methods as strings, compute an md5sum and then
'eval' the string. Hmm.

harp:~ > cat a.rb
class Module
def method_added *a, &b
p [a, b]
end
end

class C
def adding_a_method() end
end

harp:~ > ruby a.rb
[[:method_added], nil]
[[:adding_a_method], nil]

now you just need to cache them before they are added.

-a
 
J

John Carter

harp:~ > ruby a.rb
[[:method_added], nil]
[[:adding_a_method], nil]

now you just need to cache them before they are added.

The trouble is the methods get "added" every time the script gets
run. Thus depending "Makefile" like on the mtime isn't going to work.

I need a way of doing a strong hash of the method "contents" to
evaluate whether it has changed or not.

The obvious would be an "uneval" or to intercept prior to eval and
look at the string rep of the method. This has the downside of being
inappropriately sensitive to white space and comments.

A compile to byte code / interpret byte code system like yarv and
jruby would have a byte code string that would be perfect.

I think vanilla ruby has an internal 'tree of nodes' structure. I
wonder how to grab that...



John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top