oop/class/self_new.rb

tests/_examples/oop/class/self_new.rb in the metorex repository.

class Foo
  def initialize
    @x = 42
    puts "init called, @x=#{@x}"
  end

  def self.make
    puts "make: self=#{self}"
    inst = new
    puts "make: inst.class=#{inst.class}"
    inst
  end
end

f = Foo.make
puts "f.class=#{f.class}"

Output:

make: self=Foo
init called, @x=42
make: inst.class=Foo
f.class=Foo