title: about_classes.rb inspect and self in ruby
body: <p>I'm currently working on <strong>about_classes.rb</strong>. I'm confused on the concept of <strong>inspect</strong> and how it relates to <strong>self</strong>. Does calling an object automatically return the <strong>inspect</strong> method for that object?</p>
  
  <pre><code>class Dog7
      attr_reader :name
  
      def initialize(initial_name)
        @name = initial_name
      end
  
      def get_self
        self
      end
  
      def to_s
        __
      end
  
      def inspect
        "&lt;Dog named '#{name}'&gt;"
      end
    end
  
    def test_inside_a_method_self_refers_to_the_containing_object
      fido = Dog7.new("Fido")
  
      fidos_self = fido.get_self
      assert_equal __, fidos_self
    end
  
    def test_to_s_provides_a_string_version_of_the_object
      fido = Dog7.new("Fido")
      assert_equal __, fido.to_s
    end
  
    def test_to_s_is_used_in_string_interpolation
      fido = Dog7.new("Fido")
      assert_equal __, "My dog is #{fido}"
    end
  
    def test_inspect_provides_a_more_complete_string_version
      fido = Dog7.new("Fido")
      assert_equal __, fido.inspect
    end
  
    def test_all_objects_support_to_s_and_inspect
      array = [1,2,3]
  
      assert_equal __, array.to_s
      assert_equal __, array.inspect
  
      assert_equal __, "STRING".to_s
      assert_equal __, "STRING".inspect
    end
  </code></pre>