Class: Util::Args
- Inherits:
-
Object
- Object
- Util::Args
- Defined in:
- lib/util/args.rb
Overview
Functions to typecheck the arguments of a function.
Constant Summary collapse
- DEFAULT_VALUES =
If no alternative value is provided to check, these will be used.
{ Array => [], 'Boolean' => false, Class => NilClass, Complex => 0.to_c, Encoding => Encoding::UTF_8, FalseClass => true, Float => 0.0, Hash => {}, Integer => 0, Module => Kernel, NilClass => nil, Object => Object.new, Queue => Queue.new, Random => Random::DEFAULT, Range => (0..), Rational => 0.to_r, Regexp => /.*/, SizedQueue => SizedQueue.new(1), String => '', Symbol => :nil, Time => Time.now, TrueClass => false, }
- FUNCTIONS =
{ Array => :to_a, Complex => :to_c, Enumerator => :to_enum, Float => :to_f, Hash => :to_h, Integer => :to_i, Rational => :to_r, String => :to_s, Symbol => :to_sym, }
Class Method Summary collapse
-
.check(*args) ⇒ Object+
Verify whether a given argument or arguments belong to a class or can be converted into that class.
-
.check_opts(opts, *args) ⇒ Object+
Typecheck the content of an options hash, while ignoring undefined options.
Class Method Details
.check(*args) ⇒ Object+
Verify whether a given argument or arguments belong to a class or can be converted into that class. Any number of sequences of the three arguments below can be passed.
65 66 67 |
# File 'lib/util/args.rb', line 65 def self.check *args check_internal nil, *args end |
.check_opts(opts, *args) ⇒ Object+
Note:
It is not necessary to check whether opts is a Hash, the method will do it.
Typecheck the content of an options hash, while ignoring undefined options. Calls Args.check on the values associated with a given key, according to the rest of the informations given.
82 83 84 |
# File 'lib/util/args.rb', line 82 def self.check_opts opts, *args check_internal opts, *args end |