Referencing writable attributes as block parameters

J

Jamis Buck

I stumbled on this, almost by accident, and I'm curious as to whether
this is a "feature" or a "bug".

S = Struct.new( "S", :a )
s = S.new
[ 1, 2, 3, 4, 5, 6 ].each { |s.a| puts s.a }

This prints each element of the array, but what I'm curous about, is
that the block actually assigns each value to s.a.

I like this.

However, I don't want to use this if it is liable to change. Is this
simply a side-effect of the way block parameters are being handled right
now? In other words, is this something that may potentially change in
Ruby2?
 
H

Hal Fulton

Jamis said:
I stumbled on this, almost by accident, and I'm curious as to whether
this is a "feature" or a "bug".

S = Struct.new( "S", :a )
s = S.new
[ 1, 2, 3, 4, 5, 6 ].each { |s.a| puts s.a }

This prints each element of the array, but what I'm curous about, is
that the block actually assigns each value to s.a.

I like this.

However, I don't want to use this if it is liable to change. Is this
simply a side-effect of the way block parameters are being handled right
now? In other words, is this something that may potentially change in
Ruby2?

It's been in Ruby for years.

I also like it.

But I believe Matz said this feature was going away (as a result of
changing the block parameter semantics, I guess).

Matz, correct or no?

Hal
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Referencing writable attributes as block parameters"

|But I believe Matz said this feature was going away (as a result of
|changing the block parameter semantics, I guess).
|
|Matz, correct or no?

Correct.

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top