Actually, I don’t think I would ever want a reader that casts.
-a
···
–
austin ziegler
Sent from my Treo
-----Original Message-----
From: Martin DeMello
Date: 03.1.7 3.03
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subj: Re: attr_cast, one a small step for interface techniques
Tom Sawyer transami@transami.net wrote:
def attr_accessor_with_cast(harg)
attr_reader_with_cast(harg)
attr_writer_with_cast(harg)
end
Is this logically right? You;d want different casts for readers and
writers, I’d think.
martin
attr_reader :avar still works the same. no casting. having the option though
helps with automatic typing of “internally” assigned instance variables when
read out “externally”:
attr_reader :c => :to_f
@a = 1
@b = 2
@c = @a + @b
puts @c.type → Fixnum
puts c.type #–> Float
thus if an attribute is to be accessable externally as a particular type, in
this case a Float, this insures that it will be so even if you are
manipulating the instance variable internally. its not static typing, but it
dose nudge things in that direction when useful.
of course, then there’s the odder things you can do:
attr_writer :a => to_f
attr_reader :a => to_s
:-}
···
On Tuesday 07 January 2003 10:39 am, Austin Ziegler wrote:
Actually, I don’t think I would ever want a reader that casts.
-a
–
tom sawyer, aka transami
transami@transami.net
.''.
.''. . *''* :_\/_: .
:_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'.
.‘’.: /\ : ./)\ ‘:’* /\ * : ‘…’. -=:o:=-
:/:‘.:::. | ’ ‘’ * ‘.'/.’ (/’.‘:’.’
: /\ : ::::: = / -= o =- /)\ ’ *
‘…’ ‘:::’ === * /\ * .‘/.'. ‘._____
* | … : |. |’ .—"|
* | _ .–’| || | _| |
* | .-‘| __ | | | || |
.-----. | |’ | || | | | | | || |
__’ ’ /“\ | '-.”". ‘-’ ‘-.’ '` |.