Changeset 248

Show
Ignore:
Timestamp:
10/31/05 07:42:18 (3 years ago)
Author:
ged
Message:
  • Fixed lazy implementation of String#to_re
  • Added Integer#of (e.g., chars = 10.of { FaerieMUD::Character.new })
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/fm/utils.rb

    r206 r248  
    7373    ### Return the String as a regular expression that will match it. 
    7474    def to_re( casefold=false, extended=false ) 
    75         return Regexp::new( Regexp::quote(self) ) 
     75        flags = 0 
     76        flags |= Regexp::IGNORECASE if casefold 
     77        flags |= Regexp::EXTENDED if extended 
     78        return Regexp::new( Regexp::quote(self), flags ) 
    7679    end 
    7780 
     
    98101    end 
    99102 
     103end 
     104 
     105 
     106### Add some stuff to the builtin Integer class. 
     107class Integer 
     108 
     109    ### Execute the given block +n+ times and return an Array that contains the 
     110    ### results of each call. The block will be passed the iteration number. 
     111    def of 
     112        accum = [] 
     113        self.times do |i| 
     114            accum << yield( i ) 
     115        end 
     116        return accum 
     117    end 
    100118end 
    101119