Always knew i did not fully understand procs

Still not sure if I do

closed #1
This commit is contained in:
ChillerDragon 2022-11-05 16:38:54 +01:00
parent 3810a333f7
commit 6ad64d7a2d
2 changed files with 15 additions and 14 deletions

View file

@ -16,13 +16,14 @@ require_relative 'lib/teeworlds-client'
client = TeeworldsClient.new(verbose: false)
client.on_chat do |msg|
if msg.message[0] == '!'
case msg.message[1..]
when 'ping' then client.send_chat('pong')
when 'whoami' then client.send_chat("You are: #{msg.author.name}")
when 'list' then client.send_chat(client.game_client.players.values.map(&:name).join(', '))
else client.send_chat('Unkown command! Commands: !ping, !whoami, !list')
end
# note use `next` instead of `return` in the block
next if msg.message[0] == '!'
case msg.message[1..]
when 'ping' then client.send_chat('pong')
when 'whoami' then client.send_chat("You are: #{msg.author.name}")
when 'list' then client.send_chat(client.game_client.players.values.map(&:name).join(', '))
else client.send_chat('Unkown command! Commands: !ping, !whoami, !list')
end
end

View file

@ -11,13 +11,13 @@ require_relative '../lib/teeworlds-client'
client = TeeworldsClient.new(verbose: false)
client.on_chat do |msg|
if msg.message[0] == '!'
case msg.message[1..]
when 'ping' then client.send_chat('pong')
when 'whoami' then client.send_chat("You are: #{msg.author.name}")
when 'list' then client.send_chat(client.game_client.players.values.map(&:name).join(', '))
else client.send_chat('Unkown command! Commands: !ping, !whoami, !list')
end
next if msg.message[0] != '!'
case msg.message[1..]
when 'ping' then client.send_chat('pong')
when 'whoami' then client.send_chat("You are: #{msg.author.name}")
when 'list' then client.send_chat(client.game_client.players.values.map(&:name).join(', '))
else client.send_chat('Unkown command! Commands: !ping, !whoami, !list')
end
end