James Britt
2/25/2008 5:26:00 PM
Arlen Cuss wrote:
> On Mon, Feb 25, 2008 at 12:03 PM, 7stud -- <bbxx789_05ss@yahoo.com> wrote:
>
>> class Dog
>> def secret_code=(seed)
>> @secret_code = seed * 10 + 2
>> end
>> end
>>
>> d = Dog.new
>> return_val = (d.secret_code=(3) )
>> puts return_val #should this reveal the secret code?
>>
>
> Yes. What would you like it to return? The point is, you're doing
> d.secret_code = 3 -- you're saying the secret code *is* 3, so actually
> setting it to something else is a bit misleading, don't you think?
Actually, you're saying "Send the message '.secret_code=(3)' to d"
It's up to d to decide what that means and what happens next.
Suppose secret_code=(x) checks that the given value meets some criteria
(say, is a positive int), and if not, uses the value 0. I might want
the method to then return a valid value, not simply what was passed in.
--
James Britt
"We are using here a powerful strategy of synthesis: wishful thinking."
- H. Abelson and G. Sussman
(in "The Structure and Interpretation of Computer Programs)