diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2014-12-17 09:24:38 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2014-12-17 09:24:38 +0000 |
commit | 8c4a3e281338c133c6a5c6b342ecd889c6ea07c3 (patch) | |
tree | f1f4dde19d256b3dd3a6b2afcea660ffa1b48d54 /lib/slop.rb | |
parent | c258c935b6a3734a384f29295c9d320d1c9a3c30 (diff) | |
download | slop-8c4a3e281338c133c6a5c6b342ecd889c6ea07c3.tar.gz |
Document slop class methods
Diffstat (limited to 'lib/slop.rb')
-rw-r--r-- | lib/slop.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/slop.rb b/lib/slop.rb index 5e0c48b..dd2d09d 100644 --- a/lib/slop.rb +++ b/lib/slop.rb @@ -6,20 +6,50 @@ require 'slop/types' require 'slop/error' module Slop + # The current version of Slop, of course. VERSION = '4.0.0' + # Parse an array of options (defaults to ARGV). Accepts an + # optional hash of configuration options and block. + # + # Example: + # + # opts = Slop.parse(["-host", "localhost"]) do |o| + # o.string '-host', 'a hostname', default: '0.0.0.0' + # end + # opts.to_hash #=> { host: 'localhost' } + # + # Returns a Slop::Result. def self.parse(items = ARGV, **config, &block) Options.new(config, &block).parse(items) end + # Example: + # + # Slop.option_defined?(:string) #=> true + # Slop.option_defined?(:omg) #=> false + # + # Returns true if an option is defined. def self.option_defined?(name) const_defined?(string_to_option(name.to_s)) end + # Example: + # + # Slop.string_to_option("string") #=> "StringOption" + # Slop.string_to_option("some_thing") #=> "SomeThingOption" + # + # Returns a camel-cased class looking string with Option suffix. def self.string_to_option(s) s.gsub(/(?:^|_)([a-z])/) { $1.capitalize } + "Option" end + # Example: + # + # Slop.string_to_option_class("string") #=> Slop::StringOption + # Slop.string_to_option_class("foo") #=> uninitialized constant FooOption + # + # Returns the full qualified option class. Uses `#string_to_option`. def self.string_to_option_class(s) const_get(string_to_option(s)) end |