I guess a set_x(val) is the other alternative. Not sure which I dislike more
I'm amazed that you find either the above or foo(x) more appealing than simply using self.foo = x. In my personal opinion, the assignment is clear, and made clearer by the presence of 'self'.
it's just my opinion, but i think this is clear as a whistle:
require 'traits'
class Widget
traits %w( colour width height style )
end
class Button < Widget
color 'blue'
width 42
height 42
sytle 'swirly'
end
and this
require 'traits'
class C
traits(TRAITS = %w( a b c d e f ))
def initialize *args
TRAITS.each{|t| send t, args.shift}
end
end
visually the reader/writer method (writer if given arg) can be very, very nice
on the eyes and fingers - i just takes getting used to, like dropping the ';'
and '$' when moving from perl to ruby.
i espcially like that i can do
def init hash = {}
hash.each{|k,v| send k, v}
end
instead of
def init hash = {}
hash.each do |k,v|
meth = "#{ k }="
send meth, v
end
end
which always feels hackish to me
The only alternative that I would ever (personally) endorse would be some
sort of sigil for local variables like there is for global, instance, and
class variables. (Ick, more punctuation. Ick, more typying. Ick, breaks
backwards compatibility. But: at least it would be consistent with other
variables.) Something like: %foo = 12 #The randomly-chosen % means local
variable. foo = 12 #Method call with implicit self.
i think a symbol for local vars makes a TON of sense and is, really, in
keeping with ruby's design since every other scope is signaled by a symbol.
the rule could be
foo = 42
# if method exists foo=, use it
# else local var
foo := 42 # force local var
or
!foo = 42 # force local var
%foo = 42 # force local var
the thing with local vars is that, if ruby ALSO changed to lookup to search
for methods FIRST, and then to fall back on local you really wouldn't have to
use the local symbol/marker exectp in cases where a local var shadows a
method in the scope of object instance.
But...really, I'm reasonably happy with the way things are now.
me too.
cheers.
-a
···
On Thu, 6 Oct 2005, Gavin Kistner wrote:
On Oct 6, 2005, at 1:31 AM, itsme213 wrote:
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================