Created
February 27, 2014 17:36
-
-
Save jquave/9254963 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Command | |
| attr_accessor :name, :response, :needs_arg | |
| def initialize args | |
| needs_arg = false # Default | |
| args.each do |k,v| | |
| instance_variable_set("@#{k}", v) unless v.nil? | |
| end | |
| puts 'Command added: '+name | |
| end | |
| def process(arg, current_user) | |
| if(name=='nick') | |
| current_user.name=arg | |
| current_user.save! | |
| return "Name changed to #{arg}" | |
| end | |
| end | |
| def needs_arg? | |
| needs_arg | |
| end | |
| # The resultant string to send the player upon completion | |
| def result(arg, current_user) | |
| puts 'Get result' | |
| if arg.nil? | |
| puts 'Nil arg' | |
| if needs_arg? | |
| puts 'no arg' | |
| return 'Oops, did you forget to specify something?' | |
| else | |
| puts 'do resp' | |
| return response | |
| end | |
| return | |
| else | |
| # Has arg | |
| puts 'Has arg' | |
| if needs_arg? | |
| return process(arg, current_user) | |
| else | |
| return response | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment