ruby - Why do method arguments not work for assignment? -


in ruby, many languages, method's arguments not automatically assigned instance variables.

this works:

def initialize(a)   @a = end 

this doesn't:

def initialize(@a) end 

in coffeescript, example, works:

constructor: (@name) -> 

there lot of other syntactic sugar in ruby, such ||= operator, unary & on symbols, etc. there reason, technical or otherwise, why sugar isn't part of design?

edit

the scope of question not limited initialize.

in coffeescript can do

class foo   baz: (@bar) -> 

the reason matz decided way, @ least now. there's open feature request quite few supporters trying convince matz.

note should consider inheriting struct.new(:name, ...) define default constructor setting corresponding instance variables, accessors, ==, eql?, hash, etc...


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -