[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[suggestion] before_call, after_call, assert, ... why not ?

dohzya

7/2/2007 6:42:00 PM

Hi, I am a new Ruby addict, and I've a question/suggestion (sorry...).
I will try to explain myself by an example.
I tried to add assertions possibility in ruby, but I think it's not the
best way to put them hardly in method body : I want to
enable/disable/add/delete them easily. I thus added an assertion
collection in Class, but how to force methods to call them ? Redefine
__send__ ? Doesn't work, and I don't think it's a good way. In my mind,
a nice solution could be : every Proc can specify other Proc what will
be called before/after them.

some uses
---
class Truc
def my_method a, b
# here: before_call(name_of_proc, &the_proc)
before_call {|a,b| raise "not same class" unless a.class ==
b.class }
a + b
end
end
# here: before_call(method, name_of_proc=gensym("proc_"), &the_proc)
Truc.before_call :my_method, :a_name do |a,b|
raise "a > b" if a > b
end
# assert would be a shortcut for precious examples
Truc.assert :my_method, :name_of_assert, "message" do |a,b|
#...
end
---

others uses
---
# name not needed ?
Machin.after_call(:read_a_file){@file.close if @file.open?}
# Are Proc/before/after same binding ?
---
some_proc.before.each {|proc| ...}
---

Is it envisageable ? (sorry if there is an discussion on this subject
yet)

--
dohzya