Forum: Ruby-core [Feedback Request] Add support for setting instance variable in method definition

Posted by Prem Sichanugrist (Guest)
on 2013-02-25 20:20
(Received via mailing list)
Hello,

I would like to propose a feature to be added to Ruby. It was inspired 
from CoffeeScript. Before I get my hands dirty and dig in, I would like 
to hear it first if it's a good idea.

So, I want to be able to write this method:

    class person
      def initialize(name, age)
        @name = name
        @age = age
      end
    end

Into this:

    class person
      def initialize(@name, @age)
      end
    end


The benefit I'm seeing here is that we're not cluttering the initializer 
with all those obvious instance variable assignments. I also think it's 
a good syntactic sugar and it make sense after I saw all the usage from 
CoffeeScript.

If you guys thinking this is a good idea, I'll write up and submit a 
patch myself. Please let me know.

Thank you,

Prem S.
Posted by Rodrigo Rosenfeld Rosas (Guest)
on 2013-02-25 23:03
(Received via mailing list)
Please comment here:

https://bugs.ruby-lang.org/issues/5825

Em 25-02-2013 16:19, Prem Sichanugrist escreveu:
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.