K
Kale Davis
I am creating a Ruby script that basically:
1) Has a prompt that gets a command string (ex. 'edit user1 15')
2) Parses the string
3) Runs specific command (like 'edit' or 'new')
4) Repeats
From a functional level I know how to make this work, but how do I make
it dynamic in the sense that another user could easily add their own
commands by adding a new subclass?
I was thinking something like this:
class Update < Command
...
end
The problem is I don’t know how to dynamically create a new 'Update'
instance if that is the command string (ie 'update user')? I know how to
call a method using 'send' and I guess that would be another approach
maybe, but is there something for classes?
cmd = gets.chomp #ie 'update user'
c = cmd.split(' ')[0].new #simple parsing example
c.run
Thanks for any help!
Kale
1) Has a prompt that gets a command string (ex. 'edit user1 15')
2) Parses the string
3) Runs specific command (like 'edit' or 'new')
4) Repeats
From a functional level I know how to make this work, but how do I make
it dynamic in the sense that another user could easily add their own
commands by adding a new subclass?
I was thinking something like this:
class Update < Command
...
end
The problem is I don’t know how to dynamically create a new 'Update'
instance if that is the command string (ie 'update user')? I know how to
call a method using 'send' and I guess that would be another approach
maybe, but is there something for classes?
cmd = gets.chomp #ie 'update user'
c = cmd.split(' ')[0].new #simple parsing example
c.run
Thanks for any help!
Kale