2

我在一个文件中维护了一些类来运行守护进程。但我收到 lib/web_socket.rb:4:in <top (required)>: WebSocket is not a class (TypeError)错误

我已经配置了像这样的文件

require 'rubygems'
require 'daemons'
require_relative 'lib/web_socket.rb'
require_relative 'app/models/global'

而 lib web_socket.rb 是

require "socket"
require 'libwebsocket'

class WebSocket
end
4

1 回答 1

5

Websocket 是一个模块

irb(main):001:0> module Websocket
irb(main):002:1> end
=> nil
irb(main):003:0> class Websocket
irb(main):004:1> end
TypeError: Websocket is not a class
    from (irb):3
    from /home/nicco/.rbenv/versions/1.9.3-p194/bin/irb:12:in `<main>'

要么你写module WebSocket要么你写

module MyModule
  class WebSocket
    include ::WebSocket
  end
end

或者这可能是你的情况

class MyWebSocket
   include WebSocket
end
于 2013-02-12T13:12:47.633 回答