From: Radek Hnilica Date: 2002-12-19T16:09:01+09:00 Subject: Few question about IO Hello, I have few questions to wise mans. First is about IO. I want read from input stream words or longs in given endianity. How can I extend IO class to have a method to read word or long word from stream. I try class IO def getw getc()+256*getc() end public :getw end but calling: puts ARGF.getw() gives me ./dis68k.rb:45: private method `getw' called for # (NoMethodError) Next question is about Regular expression. I have a Hash filled with keyword, label pairs. Some of the keywords contains characters like: + & ( and other strange characters. Then I have a string in which I want replace all ocurrences of keywords with string the keyword must be like a word separated from other text by white spaces. Now I use this method def mangle(s, dict) dict.each_pair do |key,id| word = Regexp.quote(key) s.gsub!(%r[ #{word} ], %Q[ ]) s.gsub!(%r[^#{word} ], %Q[ ]) s.gsub!(%r[ #{word}$], %Q[ ]) end s end Is there any better and speedy way how to do it. I'm not great ruby hacker. The s.gsub!(%r[\b#{word}\b], %Q[ ]) does not work because word can be + , : , ; , ... . In my case word is any sequence of printable characters separated from others with white spaces. The main goal is replace all ocurences of given words with to that word. The table with words and its linkends is in file. The word is any sequence of printable characters separated from others by whitespaces. -- Radek Hnilica ======================================= No matter how far down the wrong road you've gone, turn back. Turkish proverb