Module: Callme::ArgsValidator
- Defined in:
- lib/callme/args_validator.rb
Overview
Helper class for arguments validation
Class Method Summary collapse
-
.block_given!(block) ⇒ Object
Checks that specified
block
is given. -
.has_key!(hash, key) ⇒ Object
Checks that specifid
hash
has a specifiedkey
. -
.is_array!(obj, obj_name) ⇒ Object
Checks that specifid
obj
is an Array. -
.is_hash!(obj, obj_name) ⇒ Object
Checks that specifid
obj
is a Hash. -
.is_symbol!(obj, obj_name) ⇒ Object
Checks that specifid
obj
is a symbol.
Class Method Details
.block_given!(block) ⇒ Object
Checks that specified block
is given
43 44 45 46 47 |
# File 'lib/callme/args_validator.rb', line 43 def block_given!(block) unless block raise ArgumentError, "Block should be given" end end |
.has_key!(hash, key) ⇒ Object
Checks that specifid hash
has a specified key
35 36 37 38 39 |
# File 'lib/callme/args_validator.rb', line 35 def has_key!(hash, key) unless hash.has_key?(key) raise ArgumentError, "#{hash} should has #{key} key" end end |
.is_array!(obj, obj_name) ⇒ Object
Checks that specifid obj
is an Array
17 18 19 20 21 |
# File 'lib/callme/args_validator.rb', line 17 def is_array!(obj, obj_name) unless obj.is_a?(Array) raise ArgumentError, "#{obj_name} should be an Array" end end |
.is_hash!(obj, obj_name) ⇒ Object
Checks that specifid obj
is a Hash
26 27 28 29 30 |
# File 'lib/callme/args_validator.rb', line 26 def is_hash!(obj, obj_name) unless obj.is_a?(Hash) raise ArgumentError, "#{obj_name} should be a Hash" end end |
.is_symbol!(obj, obj_name) ⇒ Object
Checks that specifid obj
is a symbol
8 9 10 11 12 |
# File 'lib/callme/args_validator.rb', line 8 def is_symbol!(obj, obj_name) unless obj.is_a?(Symbol) raise ArgumentError, "#{obj_name} should be a Symbol" end end |