From: Phrogz Date: 2006-12-30T08:50:07+09:00 Subject: Re: Methods validating their arguments: good or bad? Vincent Fourmond wrote: > def method(a) > entry_check > a.is_a(String) > begin > # now do something with code > exit_check > # a test on exit > end An idea: if $DEBUG def entry_check; yield; end else def entry_check; end end alias_method :exit_check, :entry_check def method( a ) entry_check{ raise "OUCH" unless a.is_a?( String ) } # meat here... exit_check{ # ... } end When the debug flag is supplied, the block is yielded and run. When not, the entry_check call still does have the overhead of a do-nothing method call, but far less than before.