Class: FunWith::Files::Utils::Opts
- Inherits:
-
Object
- Object
- FunWith::Files::Utils::Opts
- Defined in:
- lib/fun_with/files/utils/opts.rb
Class Method Summary collapse
-
.extract_opts_from_args(args) ⇒ Object
It’s tradition to pass an options hash as the last argument (creaky old tradition, named variables getting more popular) Separates out that last configuration hash, if it’s been given.
- .narrow_file_utils_options(opts, cmd) ⇒ Object
-
.narrow_options(opts, keys) ⇒ Object
Given a hash and a list of keys, return a hash that only includes the keys listed.
Class Method Details
.extract_opts_from_args(args) ⇒ Object
It’s tradition to pass an options hash as the last argument (creaky old tradition, named variables getting more popular) Separates out that last configuration hash, if it’s been given.
7 8 9 10 11 12 13 |
# File 'lib/fun_with/files/utils/opts.rb', line 7 def self.extract_opts_from_args( args ) if args.last.is_a?( Hash ) [args[0..-2], args.last ] else [args, {}] end end |
.narrow_file_utils_options(opts, cmd) ⇒ Object
20 21 22 |
# File 'lib/fun_with/files/utils/opts.rb', line 20 def self.( opts, cmd ) self.( opts, FileUtils::OPT_TABLE[ cmd.to_s ] ) end |
.narrow_options(opts, keys) ⇒ Object
Given a hash and a list of keys, return a hash that only includes the keys listed.
16 17 18 |
# File 'lib/fun_with/files/utils/opts.rb', line 16 def self.( opts, keys ) opts.keep_if{ |k,v| keys.include?( k ) } end |