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

D

dohzya

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
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top