Class: Goblin
- Inherits:
-
Object
- Object
- Goblin
- Defined in:
- lib/goblin.rb
Instance Method Summary collapse
-
#initialize(messages, user, server, port) ⇒ Goblin
constructor
A new instance of Goblin.
- #quit ⇒ Object
- #run ⇒ Object
- #say(msg) ⇒ Object
- #say_to_name ⇒ Object
Constructor Details
#initialize(messages, user, server, port) ⇒ Goblin
Returns a new instance of Goblin.
6 7 8 9 10 11 12 |
# File 'lib/goblin.rb', line 6 def initialize(, user, server, port) @messages = @user = user @socket = TCPSocket.open(server, port) say "Nick goblin_irc_thing" say "User ircbot 0 * IRCBot" end |
Instance Method Details
#quit ⇒ Object
36 37 38 39 |
# File 'lib/goblin.rb', line 36 def quit say "PART ##{@channel} : Bye bye." say 'QUIT' end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/goblin.rb', line 23 def run until @socket.eof? do msg = @socket.gets puts msg if msg.match(/End\sof/) say_to_name quit end end @socket.close end |
#say(msg) ⇒ Object
14 15 16 17 |
# File 'lib/goblin.rb', line 14 def say(msg) puts msg @socket.puts msg end |
#say_to_name ⇒ Object
19 20 21 |
# File 'lib/goblin.rb', line 19 def say_to_name @messages.each {|n| say "PRIVMSG #{@user} :#{n}"} end |