Skip to content

Proposal: .not as a Method-Based Negation Operator #76

@MatheusRich

Description

@MatheusRich

This proposal defines not as a regular method, not a keyword or special operator. It enables fluent, English-like syntax while avoiding contextual grammar rules or parser complexity.

Behavior

  • .not is a method defined on booleans and objects that implement truthiness.
  • When called, it returns the logical negation of the receiver (!self or !to_bool).
  • It works in any context where boolean negation is expected: conditionals, assignments, expressions, etc.
  • It can also be chained fluently to negate the result of a boolean-returning method call.

Examples

if user.not().logged_in?()     # reads like: "if user not logged in"
if enabled.not()               # negates the boolean value but it's better written as `if not().enabled` with an implicit self at the top level
flag = disabled.not()          # assigns the inverse of `disabled`

This avoids the need for a not keyword or ! operator entirely, and eliminates the awkwardness of unless, which many developers mentally rewrite as if not.

Benefits

  • ✅ Reads naturally in fluent method chains
  • ✅ No special grammar or contextual keywords
  • ✅ Uniform: .not() is just a method
  • ✅ Works consistently in all boolean contexts
  • ✅ Avoids unless, !, and if not rewrites

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions