class ChinoRuby::CheckValues

Public Instance Methods

check_boolean(value) click to toggle source

This function is used to check if a parameter passed to a function is a boolean, otherwise it raises an error

# File lib/chino_ruby/classes.rb, line 22
def check_boolean(value)
  if not !!value == value
    raise ArgumentError, "{#value} must be a Boolean, got #{value.inspect}"
  end
end
check_int(value) click to toggle source

This function is used to check if a parameter passed to a function is an integer, otherwise it raises an error

# File lib/chino_ruby/classes.rb, line 15
def check_int(value)
  if not value.is_a?(Integer)
    raise ArgumentError, "{#value} must be a Int, got #{value.inspect}"
  end
end
check_json(value) click to toggle source

This function is used to check if a parameter passed to a function can be converted to json, otherwise it raises an error

# File lib/chino_ruby/classes.rb, line 29
def check_json(value)
  if not value.respond_to?(:to_json)
    raise ArgumentError, "{#value} cannot be converted to json!"
  end
end
check_string(value) click to toggle source

This function is used to check if a parameter passed to a function is a string, otherwise it raises an error

# File lib/chino_ruby/classes.rb, line 8
def check_string(value)
  if not value.is_a?(String)
    raise ArgumentError, "{#value} must be a String, got #{value.inspect}"
  end
end