在哪里可以找到(或如何阅读)ruby文件? [英] Where to find (or how to read) ruby documentation?

查看:151
本文介绍了在哪里可以找到(或如何阅读)ruby文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过一些关于套接字的例子,我遇到的一个是这个,我正在努力解决这个语法。这是代码,它工作正常;

Running through some examples about sockets, one I've come across is this one and I'm struggling with the syntax a bit. Here's the code, it works just fine;

require "socket"

server = TCPServer.new(1234)

loop do
  Thread.start(server.accept) do
    |connection|
    puts "Connection started"
    while line = connection.gets
      break if line =~ /quit/ 
      puts line
      connection.puts "received"
    end

    conneciton.puts "closing the connection"
    connection.close
  end    
end

在一个小小的头痛之后,我发现server.accept代码将等到连接被检测到之前启动一个线程循环,直到quit被调用,然后关闭它。

After a little head scratching I figured out that the server.accept code would wait until a connection is detected before starting a thread that loops until quit is called, then closes it.

我想要一点帮助,我应该如何从文档中推断出这一点,而不用代码呢?我在错误的地方查找文档,还是看得见,我只是没有正确阅读?这是我一直在使用的来源;

What I would like a little help with is how I was supposed to have inferred this from the documentation without noodling around with the code? Am I looking in the wrong place for documentation or is it there in plain sight and I'm just not reading it correctly? Here's the source I've been using;

http://www.ruby-doc.org/stdlib-1.9.2/libdoc/socket/rdoc/TCPServer.html#method-i -accept

推荐答案

事实是,文档可能会更好。

The truth is, that documentation could be better.

该文档假设您已经熟悉了套接字,这与POSIX accept 调用,其文档规定,如果它们不是挂起的连接,并且没有明确地请求非阻塞操作accept()将阻止直到连接存在。 (Block是UNIX,用于特定类型的等待)。

That documentation assumes you're familiar with sockets already—that's a very similar (maybe even identical) behavior to the POSIX accept call, whose documentation states that if they're aren't pending connections and you didn't explicitly request non-blocking operation "accept() shall block until a connection is present". ("Block" is UNIX-speak for a particular type of waiting).

Ruby类中的非阻塞操作是 accept_nonblock (根据您链接的文档),因此您可以推断接受正在阻止。

Non-blocking operation in the Ruby class is accept_nonblock (according to the document you linked), so you can infer accept is blocking.

Ruby文档由志愿者维护,我相信他们很乐意接受补丁,使其更好。

The Ruby documentation is maintained by volunteers, and I'm sure they'd be happy to accept patches to make it better.

这篇关于在哪里可以找到(或如何阅读)ruby文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆