Patrick,

Thanks for the quick response. I agree that it doesn't make sense
unless I was passing the new value back to the block. I am about
15 minutes into the Picaxe and was just trying to get a handle on the
syntax. The language looks great. My brain is just hardwired with java
syntax at this point :-)

Cheers,
Jeff


-----Original Message-----
From: Patrick Hurley [mailto:phurley / gmail.com] 
Sent: Friday, March 31, 2006 5:49 PM
To: ruby-talk ML
Subject: Re: question on blocks

On 3/31/06, Jeff Thorne <jeff_thorne / yahoo.com> wrote:
> I am new to ruby from java and had a question on blocks.
>
>
>
> Can a block be applied to a writeable attribute or setter? I keep getting
> errors so I
>
> am assuming no but I wanted to double check in case my syntax is
incorrect.
>
>
>
> Thanks for the help,
>
> Jeff
>
>
>
>
>
> class Test
>
>
>
>   def initialize(one, two)
>
>     @one = one
>
>     @two = two
>
>   end
>
>
>
>   def one=(one)
>
>     @one = one;
>
>     Yield;
>
>   end
>
>
>
>  attr_reader :one, :two
>
>  attr_writer :two
>
>
>
> end
>
>
>
>
>
>
>
> test = Test.new("Hello", 2);
>
> test.one = 3 { puts "Test Block" }
>
>
>
>
>

You are correct it is not allowed, but I am curious why you want to do
this? Also if I were to go and write a setter that took a block,
wouldn't you either pass the new value into the block or use the
result of the block to set the variable?

class Test
  def a=(a)
    @a = a
    yield @a if block_given?
  end

  #or
  def b=(b)
    @b = (block_given?) ? yield b : b
  end
end

pth