Project

General

Profile

Feature #5825

Sweet instance var assignment in the object initializer

Added by goshakkk (Gosha Arinich) over 8 years ago. Updated over 6 years ago.

Status:
Assigned
Priority:
Normal
Target version:
[ruby-core:<unknown>]

Description

I'm very excited about this feature in CoffeeScript, and think it might be a nice-to-have thing in Ruby 2.0.

That's how I think it would look like:

class Me
  def initialize(@name, @age, @location); end
end

So we can declare @variables in the initializer method parameters definition to avoid assigning instance variables from method arguments by hand, like:

class Me
  def initialize(name, age, location)
    @name = name
    @age = age
    @location = location
  end
end

Want to hear what do you guys think, does that feature worth being included in 2.0?


Related issues

Has duplicate Ruby master - Feature #8563: Instance variable argumentsRejectedmatz (Yukihiro Matsumoto)Actions
Has duplicate Ruby master - Feature #12023: Allow ivars to be used as method argumentsOpenActions
Has duplicate Ruby master - Feature #12578: Instance Variables Assigned In parameters ( ala Crystal? )RejectedActions
Has duplicate Ruby master - Feature #12820: Shorter syntax for assigning a method argument to an instance variableRejectedActions
Has duplicate Ruby master - Feature #15192: Introduce a new "shortcut assigning" syntax to convenient setup instance variablesOpenmatz (Yukihiro Matsumoto)Actions

Also available in: Atom PDF