(I posted this before on the google-group rather than the usenet
group, but it seems not to have shown up. I don’t know why. If this is
a duplicate for anyone, my apologies)
def initialize(foo,bar,bat) @foo,@bar,@bat = foo,bar,bat
end
Seems clumsy and not at all DRY.
What would seem the obvious approach to me would be this:
class Foo
define_method :initialize do |@x,@y,@z| end
end
p Foo.new(1,2,3) # ==> #<Foo:0xb7cce1e4 @x=1, @z=3, @y=2>
You might want to verify that this construct is allowed in 1.9 before
using it heavily. ISTR it is deprecated.
Can someone confirm or deny that this is deprecated in 1.9?
Not just the specific case above, but the general functionality that
block parameters can be instance variables, setting the instance
variable as a side-effect of just invoking the block. For example:
Can someone confirm or deny that this is deprecated in 1.9?
I remember Matz saying some times ago that it is deprecated. I did not
post this before b/c I just cannot come up with a URL
But I remember distinctively as I really liked the syntax :((
Can someone confirm or deny that this is deprecated in 1.9?
yep, deprecated:
$ ruby1.9 -e ’
class Foo
define_method(:initialize) do |@x,@y,@z| end
end’
formal argument cannot be an instance variable
define_method(:initialize) do |@x,@y,@z| end