Project

General

Profile

Actions

Bug #15732

closed

Strict mode

Added by localhostdotdev (localhost .dev) about 5 years ago. Updated almost 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:92022]

Description

A lot of issues could be easily prevented with a strict mode, for instance:

  • Passing a block to a method that doesn't accept blocks could raise an exception, e.g. methods would be required to explicitly ask for a block (def a(..., &block))
  • $1, $2, etc. variables when matching with a regex would not be created
  • Could throw error when re-assigning constant

And maybe more controversial:

  • Using reversed keywords as argument names
  • Using method name as argument name
  • Using ambitious class/constant/method names (e.g. class A; end; class B; class A; def me; A; end; end

I'm sure there is more, using things rubocop does for instance: https://github.com/rubocop-hq/rubocop/blob/master/manual/cops.md

I could be implemented as a magic header, e.g. # strict_mode: true.

This is obviously a similar idea from Javascript's strict mode: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0