Module: Util3D

Defined in:
lib/util.rb

Class Method Summary collapse

Class Method Details

.check_arg_type(type, instance, nullable = false, array_check = false) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/util.rb', line 2

def self.check_arg_type(type, instance, nullable = false, array_check = false)
  return if(nullable && instance.nil?)
  if(array_check && instance.kind_of?(Array))
    instance.each do |item|
      check_arg_type(type, item, nullable, array_check)
    end
  else
    unless(instance.kind_of?(type))
      raise(ArgumentError::new("type mismatch: #{instance.class} for #{type}"))
    end
  end
end

.check_key_arg(arg, key) ⇒ Object



19
20
21
22
23
# File 'lib/util.rb', line 19

def self.check_key_arg(arg, key)
  if(!arg.include?(key))
    raise(ArgumentError::new("args should be contains: #{key}"))
  end
end

.raise_argurment_error(instance) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
# File 'lib/util.rb', line 15

def self.raise_argurment_error(instance)
  raise(ArgumentError::new("type mismatch: #{instance.class}"))
end