Connection.new does not allow custom arguments in subclasses

20 views
Skip to first unread message

Iñaki Baz Castillo

unread,
Apr 9, 2012, 4:52:18 PM4/9/12
to eventm...@googlegroups.com
--------------------------
class MyHandler < EM::Connection
def initialize param
@param=param
end
end

myhandler = MyHandler.new "abcd"
ArgumentError: wrong number of arguments (0 for 1)
from (irb):18:in `initialize'
from /var/lib/gems/1.9.1/gems/eventmachine-1.0.0.beta.4/lib/em/connection.rb:55:in
`block in new'
from /var/lib/gems/1.9.1/gems/eventmachine-1.0.0.beta.4/lib/em/connection.rb:49:in
`instance_eval'
from /var/lib/gems/1.9.1/gems/eventmachine-1.0.0.beta.4/lib/em/connection.rb:49:in
`new'
--------------------------


AFAIK the problem is in Connection.new:

--------------------------
# Override .new so subclasses don't have to call super and can ignore
# connection-specific arguments
#
def self.new sig, *args
allocate.instance_eval do
# Store signature
@signature = sig
# associate_callback_target sig

# Call a superclass's #initialize if it has one
initialize(*args)

# post initialize callback
post_init

self
end
end
--------------------------


Ok, but this workaround in the "new" method does not allow the above
very simple usage :(


--
Iñaki Baz Castillo
<i...@aliax.net>

Aman Gupta

unread,
Apr 9, 2012, 4:59:49 PM4/9/12
to eventm...@googlegroups.com
You cannot instantiate EM::Connection yourself. Only the reactor can do so.

Aman

> --
> You received this message because you are subscribed to the Google Groups "EventMachine" group.
> To post to this group, send email to eventm...@googlegroups.com.
> To unsubscribe from this group, send email to eventmachine...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/eventmachine?hl=en.
>

Iñaki Baz Castillo

unread,
Apr 9, 2012, 5:03:12 PM4/9/12
to eventm...@googlegroups.com
2012/4/9 Aman Gupta <themast...@gmail.com>:

> You cannot instantiate EM::Connection yourself. Only the reactor can do so.

Ok, I was trying it for an "experiment" :)

Thanks for clarifying it.

Reply all
Reply to author
Forward
0 new messages