From: Tom Sawyer Date: 2003-01-08T03:08:06+09:00 Subject: Re: attr_cast, one a small step for interface techniques 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 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 :-} -- tom sawyer, aka transami transami@transami.net .''. .''. . *''* :_\/_: . :_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'. .''.: /\ : ./)\ ':'* /\ * : '..'. -=:o:=- :_\/_:'.:::. | ' *''* * '.\'/.' _\(/_'.':'.' : /\ : ::::: = *_\/_* -= o =- /)\ ' * '..' ':::' === * /\ * .'/.\'. '._____ * | *..* : |. |' .---"| * | _ .--'| || | _| | * | .-'| __ | | | || | .-----. | |' | || | | | | | || | ___' ' /"\ | '-."". '-' '-.' '` |_. ------------------------------------------------------------