WebSocket不是类(TypeError)

时间:2013-02-12 13:08:01

标签: ruby ruby-on-rails-3.2 websocket ruby-1.9.3

我在一个文件中维护了一些类来运行守护进程。但我得到了 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 websocket.rb是

require "socket"
require 'libwebsocket'

class WebSocket
end

1 个答案:

答案 0 :(得分:4)

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