From: David Alan Black Date: 2001-08-04T19:56:29+09:00 Subject: [ruby-talk:19123] Re: Something nicer than @? Hello -- On Sat, 4 Aug 2001, MikkelFJ wrote: > One of the things I like least about Ruby is they way @ spoils otherwise > clean code visually. > Ruby is almost like an algorithmic specification from a textbook, except for > the @ in many places. I know what you mean, though in the case of class variables particularly, it's sort of useful to have something that's really noticeable, because it discourages having too many of them :-) If you want to avoid @@var syntax, you could create class accessor methods: class Module def cl_attr_accessor(*syms) syms.each do |s| instance_eval <<-EOE def #{s} @@#{s} end def #{s}=(v) @@#{s} = v end EOE end end end class Thing cl_attr_accessor :cvar def initialize Thing.cvar = 123 p Thing.cvar end end t = Thing.new # => 123 plus whatever read/write-specific flavors one wants. (Do we really not have that already?) > I suggest that we try to find a cleaner syntax for handling scope object > scope and class scope. > > One suggestion, that is harder to parse, is to use postfix ' > There is a conflict with strings, but using postfix (as opposed to prefix) > might make it work. > x' instead of @x and x'' instead of @@x > > class Point > def initialize x > x' = x > y' = y > last_x'' = x' > last_y'' = y' > end > end I don't know, but I suspect it would be literally impossible to parse. It's pretty easy to come up with examples that look like what you're describing, but which already mean something else: class Thing def abc(str); puts str; end def initialize abc' = "hello" puts abc' end end Thing.new => = "hello" puts abc I certainly wouldn't want to have to write an editor mode to handle it :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav