Advertisement
Guest User

Untitled

a guest
Apr 25th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. def function_for_1(payload)
  4. puts "hey, i'm being called in block one"
  5. puts payload
  6. end
  7.  
  8. def function_for_2(payload)
  9. puts "hey, i'm being called in block two"
  10. puts payload
  11. end
  12.  
  13. currently_in_cmd = false
  14. last_command_block = ""
  15.  
  16.  
  17.  
  18. while a = gets
  19.  
  20. case a
  21. when /cmd([0-9]+)-start/
  22. puts "Entering Command #{$1}"
  23. last_command_block = $1
  24. currently_in_cmd = true
  25. when /cmd[0-9]+-stop/
  26. puts "Exiting command #{a}"
  27. currently_in_cmd = false
  28. else
  29. if currently_in_cmd
  30. puts "CMD[#{last_command_block}]:running command: #{a}"
  31. send("function_for_#{last_command_block.gsub(" ","_")}", a)
  32. else
  33. puts "COMMAND ENCOUNTERD OUTSIDE COMMAND BLOCK"
  34. end
  35. end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement