From: Garance A Drosehn Date: 2005-08-03T09:25:21+09:00 Subject: Re: Defining regexp's and variables set by them On 8/2/05, Caleb Clausen wrote: > On 8/1/05, Garance A Drosehn wrote: > > Does ruby keep the compiled-code for a method after > > the method is finished? > > Uhhh, it's nowhere near that fancy. Ruby is a fairly traditional > interpreter, without even bytecode compilation. That's why it's > so slow. That is what I expected. So I'm back to wishing to have one method which creates all the Regexp.new's as @@variables, and then I can reference those compiled Regexp's in other methods for that class. > > But the main reason I like to split things up is that the > > regexp's involved in my real-world example are rather > > complicated. I'd like to have one section of code which > > defines the regexp's, and comments why they are the > > way they are. > > But you were just saying you don't like the regexp distant > from it's use... Almost. I was saying that I *wanted* to have them distant, because the result is more readable (for what I'm doing, IMO), and for the efficiency benefit. This may seem weird, but most of the regexp's that I'm talking about are three or four full lines long, complete with a few regexp tricks that take a few more lines of comments to explain what the regexp is doing. The case-statement is *much* more readable if the regexp's are separated from the case statement. But there is a downside from doing that, so I am looking for ideas on how I might eliminate that downside. > > What about it? My program isn't doing to_s on any regexp's > > which it defines, so I don't understand the significance of your > > question... > > Maybe not, but if it's to be a general solution, you need to handle > all this stuff. If you're just going to use it in your own program, > then that's fine but I thought you were talking about something > more general-purpose. The more general the solution, the better! :-) > You maybe be calling Regexp#to_s without knowing it if you > do something like this: > > rex1=/bar/ > rex2=/foo#{rex1}baz/ > > The interpolation calls to_s. Ah. I don't do that much, but I can understand why that would be important. Your reply and the other replies in this thread have given me quite a few good suggestions to think about. Very instructive. Thanks! -- Garance Alistair Drosehn = drosihn@gmail.com Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA