ruby picture

RCR 275: Allow instance variables as method parameters

Submitted by cyent (Tue Aug 17 18:08:54 UTC 2004)

Abstract

Allow syntax like...
  class Foo
    def current_style( a, b, c)
      @a = somefunc( a, b)
      @b = b
      @@c = c
    end
    def proposed_style( a, @b, @@c)
       @a = somefunc(a, @b)
    end
  end
  foo = Foo.new
  foo.proposed_style( 1, 2, 3)
  Results in foo.b == 2 and Foo.c == 3

Problem

Very often method parameters (especially those of "def initialize" are assigned to @instance variables. As a short cut, you should be able to put the @instance variable as an argument name meaning that it is instantly assigned on entry.

Proposal

If a variable name with an instance '@' or class variable '@@' sigil appears in the formal arguments of a method, the semantics equivalent to assignment to that @instance of @@class variable.

Analysis

It would require a syntax change.

Implementation

ruby picture
Comments Current voting

This idea has already been rejected. See https://rcrchive.net/rgarchive/rejected.html#rcr3

-- David Black


Strongly opposed 2
Opposed 0
Neutral 0
In favor 0
Strongly advocate 0
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .