Module: Ruuuby::Params
- Defined in:
- lib/ruuuby/extensions.rb
Overview
Utility functionalities for checking data types and throw exceptions.
Class Method Summary collapse
-
.check_array(param) ⇒ Boolean
True only, exception raised otherwise.
-
.check_char(param) ⇒ Boolean
True only, exception raised otherwise.
-
.check_string(param) ⇒ Boolean
True only, exception raised otherwise.
-
.not_array?(ary) ⇒ Boolean
True, if provided param is not nil and inherits from Array class.
-
.not_string?(str) ⇒ Boolean
True, if provided param is not nil and inherits from String class.
Class Method Details
.check_array(param) ⇒ Boolean
Returns true only, exception raised otherwise.
43 44 45 46 |
# File 'lib/ruuuby/extensions.rb', line 43 def self.check_array(param) raise ArgumentError.new(self::bad_type(caller_locations.first.label.to_s, Array, param)) if Ruuuby::Params::not_array?(param) true end |
.check_char(param) ⇒ Boolean
Returns true only, exception raised otherwise.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruuuby/extensions.rb', line 53 def self.check_char(param) if param == nil || !param.is_a?(String) = "a param of type{#{String.to_s}}, instead got{#{param.class.to_s}}!" elsif param.chars.length != 1 = "a String of length 1, instead got{#{param.length.to_s}}" else return true end raise ArgumentError.new("#{caller_locations.first.label.to_s} requires #{}") end |
.check_string(param) ⇒ Boolean
Returns true only, exception raised otherwise.
33 34 35 36 |
# File 'lib/ruuuby/extensions.rb', line 33 def self.check_string(param) raise ArgumentError.new(self::bad_type(caller_locations.first.label.to_s, String, param)) if Ruuuby::Params::not_string?(param) true end |
.not_array?(ary) ⇒ Boolean
Returns true, if provided param is not nil and inherits from Array class.
24 25 26 |
# File 'lib/ruuuby/extensions.rb', line 24 def self.not_array?(ary) ary == nil || !ary.is_a?(Array) end |
.not_string?(str) ⇒ Boolean
Returns true, if provided param is not nil and inherits from String class.
17 18 19 |
# File 'lib/ruuuby/extensions.rb', line 17 def self.not_string?(str) str == nil || !str.is_a?(String) end |