Class: Taski::Args
- Inherits:
-
Object
- Object
- Taski::Args
- Defined in:
- lib/taski/args.rb
Overview
Runtime arguments accessible from any task. Holds user-defined options passed by the user at execution time. Args is immutable after creation - options cannot be modified during task execution.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Get a user-defined option value.
-
#fetch(key, default = nil) { ... } ⇒ Object
Get a user-defined option value with a default.
-
#initialize(options:) ⇒ Args
constructor
A new instance of Args.
-
#key?(key) ⇒ Boolean
Check if a user-defined option key exists.
Constructor Details
#initialize(options:) ⇒ Args
Returns a new instance of Args.
11 12 13 |
# File 'lib/taski/args.rb', line 11 def initialize(options:) @options = .dup.freeze end |
Instance Method Details
#[](key) ⇒ Object?
Get a user-defined option value
18 19 20 |
# File 'lib/taski/args.rb', line 18 def [](key) @options[key] end |
#fetch(key, default = nil) { ... } ⇒ Object
Get a user-defined option value with a default
27 28 29 30 31 32 33 34 35 |
# File 'lib/taski/args.rb', line 27 def fetch(key, default = nil, &block) if @options.key?(key) @options[key] elsif block block.call else default end end |
#key?(key) ⇒ Boolean
Check if a user-defined option key exists
40 41 42 |
# File 'lib/taski/args.rb', line 40 def key?(key) @options.key?(key) end |