title: Ruby - class inheritance and redefining initialize to work with factory methods
body: <p>I'm not sure what is happening with the inheritance here. I get a nil value for this code. but when i don't override the initialise method and pass in a hash argument, like the Temperature class accepts (:c => 50) it works fine. </p>
  
  <p>I think that maybe the factory methods are calling the initialize method again which is now changed? but then I would have thought that I get a loop..</p>
  
  <p>thank you. below is the code segment. it's my solution to an r-spec teaching resource</p>
  
  <p>i think my question is:</p>
  
  <p>why is the self.from_celsius method creating a new instance object that doesn't call the conversion method as the initialize method defined in Temperature is supposed to? </p>
  
  <pre><code>class Temperature
  
      ######################## -- getter methods 
      def in_fahrenheit 
          @in_fahrenheit
      end 
  
      def in_celsius
          @in_celsius
      end
  
      ######################## -- initialize and call the calculations
      def initialize(hash)
          @options = hash
          conversion
      end
  
      ######################## -- calculations
      def conversion
          @options.key?(:c) ? @in_fahrenheit = (9.0/5.0*@options[:c].to_f) + 32.0 : @in_fahrenheit = @options[:f]
          @options.key?(:f) ? @in_celsius = (5.0/9.0)*(@options[:f].to_f - 32.0) : @in_celsius = @options[:c]
      end 
  
      ######################## -- factory methods
      def self.from_celsius(c)
          self.new(:c =&gt; c)
      end
  
      def self.from_fahrenheit(f)
          self.new(:f =&gt; f)
      end
  end
  
  
  class Celsius &lt; Temperature
      def initialize(c)
          Temperature.from_celsius(c)
      end
  end
  
  class Fahrenheit &lt; Temperature
      def initialize(f)
          Temperature.from_fahrenheit(f)
      end
  end
  
  
  x = Celsius.new(50).in_celsius
  
  puts x.nil?
  #=&gt; true
  </code></pre>