diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 16:10:25 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 16:10:25 +0000 |
commit | 2a312300798d1da4aa666a0888f8a94a5ee5f245 (patch) | |
tree | 478345bf12957dc9c5f3402e65210c9d9b1b7c5d /lib/slop/option.rb | |
parent | 899830973c6bed61d1230894f6a70cf4fe4e8339 (diff) | |
download | slop-2a312300798d1da4aa666a0888f8a94a5ee5f245.tar.gz |
Yield option arguments to option blocks
Diffstat (limited to 'lib/slop/option.rb')
-rw-r--r-- | lib/slop/option.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/slop/option.rb b/lib/slop/option.rb index a635270..b8f1167 100644 --- a/lib/slop/option.rb +++ b/lib/slop/option.rb @@ -4,13 +4,14 @@ module Slop help: true } - attr_reader :flags, :desc, :config, :count + attr_reader :flags, :desc, :config, :count, :block attr_writer :value - def initialize(flags, desc, **config) + def initialize(flags, desc, **config, &block) @flags = flags @desc = desc @config = DEFAULT_CONFIG.merge(config) + @block = block reset end @@ -27,6 +28,7 @@ module Slop def ensure_call(value) @count += 1 @value = call(value) + block.call(@value) if block.respond_to?(:call) end def call(_value) |