title: How to access "self" inside the scope of a class?
body: <p>I've crossed an interesting problem.</p>
  
  <p>Suppose we have a class, and in its constructor we take a boolean as an argument. How can I define methods inside the class based on the instance's condition/boolean? For example:</p>
  
  <pre><code>class X():
      def __init__(self, x):
          self.x = x
      if self.x == true: # self is unreachable outside a method.
          def trueMethod():
              print "The true method was defined."
      if self.x == false: # self is unreachable outside a method.
          def falseMethod():
              print "The false method was defined."
  </code></pre>