Forum: Ruby before_call, after_call, assert, ... why not ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E257c17034ca33ea3f75574f6b22e402?d=identicon&s=25 dohzya (Guest)
on 2007-07-02 20:42
(Received via mailing list)
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
# 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
# assert would be a shortcut for precious examples
Truc.assert :my_method, :name_of_assert, "message" do |a,b|

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

Is it envisageable ? (sorry if there is an discussion on this subject
This topic is locked and can not be replied to.