(SOT) Change in em-http-request: 0.3.0 => 1.0.0

I am trying to bring some older code up to date. It works fine with
em-request-http 0.3.0. With 1.0.0 it breaks, revealing my lack of
understanding Ruby, among other things. The following code reveals the
problem:

require 'rubygems'
require 'eventmachine'
#gem 'em-http-request', '=0.3.0'
require 'em-http-request'

class PhrcRequest < EM::HttpRequest
  def initialize(*args)
    puts "HERE"
    super(args)
  end
end

r = PhrcRequest.new(‘http://example.com/’)

puts r.inspect

With em-request-http 1.0.0 (the newest version on my system), the output is:

#<EventMachine::HttpConnection:0x7fb4d804a120 @middleware=[], @deferred=true,
@uri="http://example.com/", @connopts=#<HttpConnectionOptions:0x7fb4d804a580
@port=80, @tls={}, @proxy=nil, @inactivity_timeout=10, @host="example.com",
@connect_timeout=5>>

With version 0.3.0 (the gem statement uncommented), the output is:

HERE
#<PhrcRequest:0x7f130c1891a8 @uri=#<Addressable::URI:0x3f89860c4730 URI:http://example.com/>>

Can someone explain to me how calling new() for one class returns an object of
another class? And how I can work around it. And is this a bug in
EM::HttpRequest that I should report?

TIA,
  Jeffrey

r = PhrcRequest.new(‘http://example.com/’)

puts r.inspect

With em-request-http 1.0.0 (the newest version on my system), the output is:

#<EventMachine::HttpConnection:0x7fb4d804a120 @middleware=[], @deferred=true,
@uri="http://example.com/", @connopts=#<HttpConnectionOptions:0x7fb4d804a580
@port=80, @tls={}, @proxy=nil, @inactivity_timeout=10, @host="example.com",
@connect_timeout=5>>

With version 0.3.0 (the gem statement uncommented), the output is:

HERE
#<PhrcRequest:0x7f130c1891a8 @uri=#<Addressable::URI:0x3f89860c4730 URI:http://example.com/>>

Can someone explain to me how calling new() for one class returns an object of
another class? And how I can work around it. And is this a bug in
EM::HttpRequest that I should report?

new is a method that can be overridden like any other, as you can see
at https://github.com/igrigorik/em-http-request/blob/master/lib/em-http/request.rb
I don't know anything about the innards of em-http-request, so I can
only advise searching through the source to see where the
functionality you were trying to override has gone.

Fred

Quoting Jeffrey L. Taylor <ror@abluz.dyndns.org>:

I am trying to bring some older code up to date. It works fine with
em-request-http 0.3.0. With 1.0.0 it breaks, revealing my lack of
understanding Ruby, among other things. The following code reveals the
problem:

require 'rubygems'
require 'eventmachine'
#gem 'em-http-request', '=0.3.0'
require 'em-http-request'

class PhrcRequest < EM::HttpRequest
  def initialize(*args)
    puts "HERE"
    super(args)
  end
end

r = PhrcRequest.new(‘http://example.com/’)

puts r.inspect

With em-request-http 1.0.0 (the newest version on my system), the output is:

#<EventMachine::HttpConnection:0x7fb4d804a120 @middleware=[], @deferred=true,
@uri="http://example.com/", @connopts=#<HttpConnectionOptions:0x7fb4d804a580
@port=80, @tls={}, @proxy=nil, @inactivity_timeout=10, @host="example.com",
@connect_timeout=5>>

With version 0.3.0 (the gem statement uncommented), the output is:

HERE
#<PhrcRequest:0x7f130c1891a8 @uri=#<Addressable::URI:0x3f89860c4730 URI:http://example.com/>>

Can someone explain to me how calling new() for one class returns an object of
another class? And how I can work around it. And is this a bug in
EM::HttpRequest that I should report?

Use the source! Looking at the 1.0.0 code, it overrides self.new(), doesn't
call initialize() and returns an HttpConnection. This strikes me as abuse of
the language and certainly violates the principle of least surprise. It also
effectively blocks inheritance. Can anyone tell me how this is not a bug?

Jeffrey