Class: IrcClient
- Inherits:
-
Object
- Object
- IrcClient
- Defined in:
- lib/irc_client.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(server, nick, options = {}) ⇒ IrcClient
constructor
A new instance of IrcClient.
- #join(channel, key = nil) ⇒ Object
- #leave ⇒ Object
- #quit ⇒ Object
- #run(&block) ⇒ Object
- #say(message) ⇒ Object
Constructor Details
#initialize(server, nick, options = {}) ⇒ IrcClient
Returns a new instance of IrcClient.
14 15 16 17 18 19 |
# File 'lib/irc_client.rb', line 14 def initialize(server, nick, = {}) @socket = TCPSocket.open(server, [:port] || 6667) socket.puts "PASS #{[:password]}" if [:password] socket.puts "NICK #{nick}" socket.puts "USER #{nick} #{nick} #{nick} :#{nick}" end |
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
12 13 14 |
# File 'lib/irc_client.rb', line 12 def channel @channel end |
#socket ⇒ Object
Returns the value of attribute socket.
12 13 14 |
# File 'lib/irc_client.rb', line 12 def socket @socket end |
Instance Method Details
#join(channel, key = nil) ⇒ Object
21 22 23 24 |
# File 'lib/irc_client.rb', line 21 def join(channel, key = nil) self.channel = channel socket.puts "JOIN ##{self.channel} #{key}".strip end |
#leave ⇒ Object
30 31 32 |
# File 'lib/irc_client.rb', line 30 def leave socket.puts "PART ##{channel}" end |
#quit ⇒ Object
38 39 40 41 |
# File 'lib/irc_client.rb', line 38 def quit socket.puts "QUIT" socket.gets until socket.eof? end |
#run(&block) ⇒ Object
26 27 28 |
# File 'lib/irc_client.rb', line 26 def run(&block) instance_eval(&block) if block_given? end |
#say(message) ⇒ Object
34 35 36 |
# File 'lib/irc_client.rb', line 34 def say() socket.puts "PRIVMSG ##{channel} :#{}" if channel end |