From: harryo@... (Harry Ohlsen) Date: 2001-02-01T03:40:02+09:00 Subject: [ruby-talk:10181] Require loops I've written a number of numeric types that I want to be able to use anywhere I could a Fixnum or Float. So, I've written code for each of +, -, * and / that check what the type of the "other" argument is and do appropriate things. However, there is the issue of handling things like ... fred = 10 * What I did was write a separate file called CommuteTypes.rb that redefines +, -, * and / for each of the built-in types, so that if the "other" is one of my types it swaps the arguments around and calls the appropriate method of that type. Ie, it effectively changes the example above to be fred = * 10 Since the * method for my type understands what to do when "other" is, say, a Fixnum, all is well. I have two question: 1. Is there a better way to handle this using some language feature I am not aware of? 2. I have put a "require 'CommuteTypes'" into each of the .rb files that defines one of my types. However, some of the types require the other types, so I end up with a load loop. I was able to get around this by putting the require statements inside things like if !defined? OneOfMyTypes require 'OneOfMyTypes' end This seems a little messy. Is there a better way to do it? In fact, I'm wondering whether the language could be changed such that any recursive requires are simply ignored, rather than being considered an error? This kind of thing happens all the time in C/C++ and we use an "#ifdef" idiom there which is equivalent to the above. I'm just wondering whether there is any point to imposing that on the programmer when I would guess that the programmer's intent is, as far as I can see, would always satisfied by just ignoring recursive requests? Or am I missing something here?