How to pass the given block to other method?

Hi, in case Ia method allows a block:

  SomeModule.connect_tcp("1.2.3.4", 23) do |connection|
    connection.send_data "hello"
  end

how to wrap this into other method? This is what I want to achieve:

···

---------------------------------------------------------
  module OtherModule
    def self.connect(host, port)
      SomeModule.connect_tcp host, port
    end
  end

  OtherModule.connect("1.2.3.4", 23) do |connection|
    connection.send_data "hello"
  end
---------------------------------------------------------

Unfortunatelly it doesn't work. I expect I must pass the given block
to the SomeModule.connect_tcp method in someway I don't know.

Thanks for any help.

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

Autoanswer:

···

2011/3/11 Iñaki Baz Castillo <ibc@aliax.net>:

---------------------------------------------------------
module OtherModule
def self.connect(host, port)
SomeModule.connect_tcp host, port
end
end

OtherModule.connect("1.2.3.4", 23) do |connection|
connection.send_data "hello"
end
---------------------------------------------------------

Unfortunatelly it doesn't work. I expect I must pass the given block
to the SomeModule.connect_tcp method in someway I don't know.

---------------------------------------------------------
module OtherModule
   def self.connect(host, port, &block)
     SomeModule.connect_tcp host, port, &block
   end
end

OtherModule.connect("1.2.3.4", 23) do |connection|
   connection.send_data "hello"
end
---------------------------------------------------------

:slight_smile:

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