Class: Mcoin::Command::Base::Option
- Inherits:
-
Object
- Object
- Mcoin::Command::Base::Option
- Defined in:
- lib/mcoin/command/base.rb
Overview
Option Register
Instance Method Summary collapse
-
#initialize(mode, name, *args) ⇒ Option
constructor
A new instance of Option.
- #register(command) ⇒ Object
- #register_as_multiple(command) ⇒ Object
- #register_as_single(command) ⇒ Object
Constructor Details
#initialize(mode, name, *args) ⇒ Option
Returns a new instance of Option.
46 47 48 49 50 |
# File 'lib/mcoin/command/base.rb', line 46 def initialize(mode, name, *args) @mode = mode @name = name.to_sym @args = args end |
Instance Method Details
#register(command) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/mcoin/command/base.rb', line 52 def register(command) case @mode when :single then register_as_single(command) when :multiple then register_as_multiple(command) end end |
#register_as_multiple(command) ⇒ Object
63 64 65 66 |
# File 'lib/mcoin/command/base.rb', line 63 def register_as_multiple(command) command.option[@name] ||= [] command.on(*@args, ->(value) { command.option[@name].push(value) }) end |
#register_as_single(command) ⇒ Object
59 60 61 |
# File 'lib/mcoin/command/base.rb', line 59 def register_as_single(command) command.on(*@args, ->(value) { command.option[@name] = value }) end |