Advertisement
Guest User

Untitled

a guest
Apr 25th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env ruby
  2.  
  3.  
  4.  
  5.  
  6. def function_for_1
  7.         puts "hey, i'm being called in block one"
  8. end
  9.  
  10. def function_for_2
  11.         puts "hey, i'm being called in block two"
  12. end
  13.  
  14.  
  15.  
  16. currently_in_cmd = false
  17. last_command_block = ""
  18.  
  19. STDIN.read.split("\n").each do |a|
  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(" ","_")}")
  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