How can I get this Java-like effect in Ruby?
class Outer {
final boolean switch
public Outer(boolean someSwitch) {
switch = someSwitch
}
class Inner {
public void doSomething() {
if (switch) {
//behave like this
} else {
//behave like that
}
}
}
Never mind that the switch has to be final; in Scala, it doesn't. Anyway. My Inner class lives within the scope of an Outer instance, and that is how I like it. And I don't have to pass the switch to each individual inner instance.
In Ruby, I can nested a class inside another, but it doesn't mean anything beyond a namespace. How can I get the effect that I want? I know the question is a little vague, so feel free to take a stab at it even if you're not sure.