Refuse_nil

I’m seriously thinking about a refinement for Hash and Struct.. maybe more.. refusing nil as a value.

I don’t think ’nil’ is a value that should be deliberately set. It should be an internal value, indicating ’not defined'.

  hsh = {name: 'Olle', age: 12}

  # and let's say every user should have hobbies.
  # But since Olle doesn't have a hobby: set it to nil.

  hsh[:hobbies] = nil

  # now you don't know if the key is missing.. or the value is an actual nil.
  # You would have to double-check:
  hsh.key?(:hobbies) && hsh[:hobbies]

  # Same with Struct.
  # Data = Struct.new(:id, :name, :model)
  # item = Data.new
  # item nwo has id: nil, name:nil and model: nil

What if I need a NO_VALUE_INDICATOR or a DEFAULT_INDICATOR? Answer: Write them. Or use ‘false’, .zero?, .empty? .blank? Do not use ’nil’.