module URITemplate::RFC6570::Utils

@private

Public Instance Methods

def?( value ) click to toggle source

Returns true iff the value is `defined` [RFC6570 Section 2.3](tools.ietf.org/html/rfc6570#section-2.3)

The only undefined things are:

  • nil

  • arrays containing no defined value

  • associative arrays/hashes containing no defined value

Things that are always defined:

  • Strings, independent of the length

# File lib/uri_template/rfc6570.rb, line 54
def def?( value )
  case( value )
  when nil  then
    false
  when Hash then
    value.any?{|_, v| !v.nil? }
  when Array then
    if value.none?
      false
    elsif value[0].kind_of?(Array)
      value.any?{|_,v| !v.nil? }
    else
      value.any?{|v| !v.nil? }
    end
  else
    true
  end
end