# # Hash with keys can be accessed as methods # e.g. h = Hash.new # h['key'] = 1 # h.key = 2 # puts h.key # class Hash def method_missing(method_name, *args) name = method_name.to_s if name.ends_with?('=') self[ name.chop ] = args[0] else self[ name ] end end end class String def ends_with?(substr) len = substr.length self.reverse() [0 .. len-1].reverse == substr end def starts_with?(substr) len = substr.length self[0 .. len-1] == substr end alias start_with? starts_with? alias begin_with? starts_with? alias begins_with? starts_with? alias end_with? ends_with? # String each() operator reads line-by-line # These functions return char-by-char def each_char self.each_byte{|x| yield x.chr } end def collect_char r = [] self.each_byte{|x| r << x.chr } r end end def read_ini_file( filename ) h = Hash.new File.open(filename,'r'){|f| f.each{|line| next if line.begins_with? '#' next if not line.include? '=' m = line.match /\s*([a-z0-9_]+)\s*=(.+)/ h[m[1]] = m[2].strip } } return h end def pause print "\n\n\nHit ENTER to continue\n\n\n" readline end def message str print str + "\n" end def debug str print str + "\n" end