Ruby is nice language, but…

It won’t be about performance. It will be about documentation. Ruby is beautiful language and it gives a lot of fun when coding. But there is some wide gap between tutorials and standard library documentation. RDoc pages are very useful when You know exactly what to search for… But in case You know more that after average tutorial or basic book (like Programming in Ruby) it is sometimes hard to find useful information in short time. Lucky we have Google…

Let examine Net::HTTP.start method. From it’s documentation (search for start (Net::HTTP) in Methods window and follow link – it is example why frames in HTML should be banned) would You know how to set port to which it should connect?

Opens TCP connection and HTTP session.

When this method is called with block, gives a HTTP object to the block and closes the TCP connection / HTTP session after the block executed.

When called with a block, returns the return value of the block; otherwise, returns self.

So how to connect to non standard port? And the answer is just like that:

conn = Net::HTTP.start('localhost', 81)

That’s it. And I was searching long, long time…

Could someone recommend good book about Ruby (not language itself, since it is very well described in Programming Ruby: The Pragmatic Programmers’ Guide, Second Edition, I have only remarks to standard library description, rest is top-notch) ?

Join the Conversation

2 Comments

  1. Yeah… This entry is over one year old ;)

    I have both books You have mentioned. Indeed Cookbook is full of valuable examples, like most of O’Reilly cookbooks.

    And The Ruby Way is must read for everyone who wants to learn Ruby well. Only thing I dislike in this book is index – way to simple…

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.