From: Hugh Sasse Staff Elec Eng Date: 2001-11-22T19:32:43+09:00 Subject: [ruby-talk:26125] Dynamic programming and Unit Testing. I'm trying to understand how to use the dynamic featurs of Ruby to good effect, together with encapsulation. I have a base class that is pretty much virtual, so that in use it will always be subclassed. Let's call it Knot for now. So I will want to do increasingly sophisticated tests on it, with things like class ThumbKnot < Knot ... end class ReefKnot < Knot ... end class AlpineButterflyKnot < Knot ... end Ideally, I would create these in my testing classes, so that each test is distinct, the information relating to the test is held locally to it, and is Protected (in the inheritance sense). However, one cannot define a class in a method. This presumably relates to class names being constants, but I'm not sure. Futhermore, one cannot define methods within a method definition. I can create singleton classes, ("class << aknot") but these are not proper subclasses. I think I can nest class definitions so long as I'm not in a method: class This class That end end so this may solve my problem. So do I do something like: class Testing_Knot_with_ThumbKnot < RUNIT::TestCase class ThumbKnot < Knot def tie end end def test_ThumbKnot end end and so on? I think I need to know a bit more explicitly what the nesting rules are for these things, and whether there is some simple underlying principle that would make such rules easy to remember. Thank you, Hugh