19 ms·
I would add coffeescript-style instance variable setting to ruby method definitions like so: def initialize(foo, bar, baz) @foo=foo @bar=bar @
by ericb 15y ago
I would add coffeescript-style instance variable setting to ruby method definitions like so:
def initialize(foo, bar, baz)
@foo=foo
@bar=bar
@baz=baz
end
Would now be:
def initialize(@foo, @bar, @baz)
end
This would save hundreds of lines of code in large programs-- lines which could no longer be a source of typos or errors.
Oh, also I'd make binding_of_caller work.
- Miky 15y agoI was under the impression that you could already do that in Ruby, although I don't use it much and very well could be wrong. Edit: Never mind, I just tried it and got an error. Weird. I could have sworn I'd seen it done somewhere.
- orangecat 15y agoThat would be my answer for Python as well. Interesting that both languages have the same flaw, when they're normally very good about eliminating boilerplate.
- raganwald 15y agoThat falls out of destructuring, so if you order def foo(@bar) now, we'll throw in a free {@kbar, fu: @bar, blitz: [@first, @rest...]} = someHash At no extra charge.
- ericb 15y agoPerhaps it is the wording, but I actually have no understanding of what you just said. I'm interested though, so can you expand on that a bit?
- raganwald 15y agoCoffeeScript implements def foo (@bar, @blitz) using destructuring assignment, a general facility that applies to assignment statements, not just function calls.