A
Andreas S
I often found my self retyping a lot of lines when experimenting or testing=
in irb after making some changes. I suppose I should be able to avoid it w=
ith a better planning, but...
Anyhow, I wrote a function in my .irbrc that reloads the listed file and it=
s dependencies so that I can work on my text editor (btw, I'm using vim) an=
d have irb automatically rerun my script after I made my changes (in the sp=
irit of Zen test's autotest). Something like this:
def auto_load main, *dependencies
Thread.new do
main_mtime =3D File.mtime main; load main
dep_mtime =3D {}
dependencies.each {|f| dep_mtime[f] =3D File.mtime f; load f }
loop do
change =3D false
dependencies.each do |f|
if (t =3D File.mtime f) > dep_mtime[f]
change =3D true; dep_mtime[f] =3D t; load f
end
end
if (t =3D File.mtime main) > main_mtime or change
main_mtime =3D t; load main
end
sleep 1
end.run
end
It's rather crude, perhaps even a clumsy irb practice. I thought maybe othe=
r people have the same need and probably with a better solution. Does anybo=
dy have a suggestion for a better solution or a better practice when experi=
menting or testing with irb? Is there a ruby gem that would be helpful?
You may say "what's wrong with writing in test.rb and retyping load 'test.r=
b' after making changes?". Well, it's kind of nice to automate that, plus i=
f the change is in one of the 'require'd files, I need to re'load' that.
-andre
_________________________________________________________________
Connect and share in new ways with Windows Live.
http://www.windowslive.com/share.html?ocid=3DTXT_TAGHM_Wave2_sharelife_0120=
08=
in irb after making some changes. I suppose I should be able to avoid it w=
ith a better planning, but...
Anyhow, I wrote a function in my .irbrc that reloads the listed file and it=
s dependencies so that I can work on my text editor (btw, I'm using vim) an=
d have irb automatically rerun my script after I made my changes (in the sp=
irit of Zen test's autotest). Something like this:
def auto_load main, *dependencies
Thread.new do
main_mtime =3D File.mtime main; load main
dep_mtime =3D {}
dependencies.each {|f| dep_mtime[f] =3D File.mtime f; load f }
loop do
change =3D false
dependencies.each do |f|
if (t =3D File.mtime f) > dep_mtime[f]
change =3D true; dep_mtime[f] =3D t; load f
end
end
if (t =3D File.mtime main) > main_mtime or change
main_mtime =3D t; load main
end
sleep 1
end.run
end
It's rather crude, perhaps even a clumsy irb practice. I thought maybe othe=
r people have the same need and probably with a better solution. Does anybo=
dy have a suggestion for a better solution or a better practice when experi=
menting or testing with irb? Is there a ruby gem that would be helpful?
You may say "what's wrong with writing in test.rb and retyping load 'test.r=
b' after making changes?". Well, it's kind of nice to automate that, plus i=
f the change is in one of the 'require'd files, I need to re'load' that.
-andre
_________________________________________________________________
Connect and share in new ways with Windows Live.
http://www.windowslive.com/share.html?ocid=3DTXT_TAGHM_Wave2_sharelife_0120=
08=