From: Alexander Bokovoy Date: 2001-12-19T00:18:22+09:00 Subject: [ruby-talk:28869] Re: ANN: rdoc-alpha-3 --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=koi8-r Content-Disposition: inline On Tue, Dec 18, 2001 at 11:07:47PM +0900, Dave Thomas wrote: > > > As usual, all comments, bugs etc gratefully received. > > Run against JTTUI (jttui.200110311410) generates an error in rdoc: [skip] > misc/orphanscanner.rb > misc/numdigits.rb > > Any chance you could send me the file that's breaking it? jtutil.rb -- / Alexander Bokovoy $ cat /proc/identity >~/.signature `Senior software developer and analyst for SaM-Solutions Ltd.` --- Nov 21 20:58:58 alconost kernel: VFS: Busy inodes after unmount. Self-destruct in 5 seconds. Have a nice day... --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=koi8-r Content-Disposition: attachment; filename="jtutil.rb" # # Jakub Travnik's utility functions, used by jttui and jc file commander # # utilities # enlarge String class with prefix? and suffix? tests # I would like these to be in standard library # # str.prefix?(parameter)-> false if parameter is not prefix of str # str.suffix?(parameter)-> false if parameter is not suffix of str # non false value otherwise # class String def prefix?(p) index(p)==0 end def suffix?(s) part=self[-s.length..-1] part == s or s.length == 0 end end # # reraising exception with updated caller def reraise raise $!.class, $!.message, caller[1..-1] end # # clipping values into given numeric range # # note: return value is invalid for inversed ranges class Range def clip(value) return self.begin if value < self.begin if exclude_end? return self.end-1 if value >= self.end else return self.end if value > self.end end value # btw: methods begin and end break formating in emacs end end class Array # foldr and foldl applies function (block) to pair generated from # array element and previous value, the first previous value is parameter # I would like these to be in standard library # they allow many uses, consider these # sum=ary.foldr(0){|a,b| a+b} # product=ary.foldr(1){|a,b| a*b} # object_of_minimal_value=ary.foldr(ary.last){|a,b| a.valueb.value ? a : b} # lisp_like_list=ary.foldr(nil){|a,b| [a,b]} # reversed_lisp_like_list=ary.foldl(nil){|a,b| [a,b]} # and so on ... :-) # yes, they are not fast, but I would use C if I want speed # foldr start from right: [1,2,3].foldr(4) &f => f(1,f(2,f(3,4))) def foldr(right,&block) self.reverse_each{|elt| right=block.call(elt,right)} right end # foldl start from left: [1,2,3].foldr(0) &f => f(f(f(0,1),2),3) def foldl(left,&block) self.each{|elt| left=block.call(left,elt)} left end end module DelayedNotify # This common pattern found in jttuistd.rb # When is it useful? # You want setter methods to update something (in case of jttuistd.rb # usually update is repainting). It is nice when it works automatically, but # this may cause slow down. Delayed notify allows to delay update where # necessary. # # class AverageOfTwo # attr_reader :valueone, :valuetwo, :average # include DelayedNotify # def initialize(v1,v2) # @valueone=v1; @valuetwo=v2 # delayednotify_init { @average=(@valueone+@valuetwo)/2.0 } # notify # end # def valueone=(v); @valueone=v; notify; end # def valuetwo=(v); @valuetwo=v; notify; end # end # aot=AverageOfTwo.new(1,3) # p aot.average # aot.valueone=6 # p aot.average # aot.delayednotify { # aot.valueone=20 # no update here # aot.valuetwo=10 # no update here # } # <-- update occur here # p aot.average # def delayednotify_init(&block) # set update block @delayednotify_blocked=0 @delayednotify_block=block end def notify # notify update method unless blocked if @delayednotify_blocked == 0 @delayednotify_block.call(self) if @delayednotify_block end end def delayednotify(&block) # run block with disabled update, then enable update and notify @delayednotify_blocked+=1 yield(self) ensure @delayednotify_blocked-=1 notify end def disablednotify(&block) # run block with disabled update, then enable update without notify @delayednotify_blocked+=1 yield(self) ensure @delayednotify_blocked-=1 end end # DEBUGING SUPPORT # change output file or device as you wish, # I prefer debug.log file or /dev/tty3 (on tty1 emacs, on tty2 tested program) # def debug_output_file 'debug.log' end def debug(*p) File.open(debug_output_file,"a") do |f| f.write caller[2]+"=>> " # there is [0]=open [1]=debug [2]=real caller p.each_index{ |i| f.write ", " if i>0 f.write p[i].inspect } f.write "\r\n" # \r\n" # adjust as you need f.flush end end debug 'NEW DEBUG SESSION', Time.now.to_s if test(?e,debug_output_file) --qMm9M+Fa2AknHoGS--