How to pass the given block to other method?

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

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.


--=20
I=C3=B1aki Baz Castillo
<[email protected]>
 
I

Iñaki Baz Castillo

2011/3/11 I=C3=B1aki Baz Castillo said:
---------------------------------------------------------
=C2=A0module OtherModule
=C2=A0 =C2=A0def self.connect(host, port)
=C2=A0 =C2=A0 =C2=A0SomeModule.connect_tcp host, port
=C2=A0 =C2=A0end
=C2=A0end

=C2=A0OtherModule.connect("1.2.3.4", 23) do |connection|
=C2=A0 =C2=A0connection.send_data "hello"
=C2=A0end

Autoanswer:


---------------------------------------------------------
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
---------------------------------------------------------

:)



--=20
I=C3=B1aki Baz Castillo
<[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top