On Monday 23 August 2004 02:11 pm, Gavin Sinclair wrote:
> I know of one person who uses it, but his keyboard seems to lack a
> shift key and parentheses, so perhaps his underscore key is also
> broken
lol
> I dislike 'attr', as the attr_* methods have a clearer intent and
> consistent style.
That's interesting. I'm preparing to release Duckbill and it includes
modifications to the attribute methods. This is the reason I had asked
because I was thinking of using attr for my new primary method. Basically
works like this:
attr :r, :w=
Which creates a reader and a writer. (It can do other cool things but I'll
save those for release). Its there a better name?
def_attr
attr_def
attribute
attributes
> I do wish, however, that Ruby collected attribute metadata so you
> could use it later in the class, to wit:
>
> class X
> attr_reader
, :y
> attr_accessor :z
>
> attributes.include?
# -> true
> attribute(
).writer? # -> false
> end
>
> That particular API is the result of less thinking than typing, so
> it's not a literal suggestion; just a germ of an idea.
Actually I can do this with my library (I think). In my library every
attribute method routes through a single master function called
"define_attribute". So as long as you use the new methods (and not any of the
aliased old ones) its a piece of cake. Maybe that's a good reason to loose
the old functionality altogether.
> > Secondly, if I create a module, is it possible to "reload" it into
> > another namespace? ex-
> >
> > module ObjectModifier
> > class Object
> > def new_method
> > ...
> > end
> > end
> > end
> >
> > # reload into toplevel
> > reinclude ObjectModifier #?
>
> s/reinclude/include/ and give it a try. I think you'll be pleasantly
> surprised.
I've tried it three times. Unless I'm missing something it doesn't fly:
module Tes
class Object
def t
puts "x"
end
end
end
include Tes
o = Object.new
o.t
#=> undefined method `t' for #<Object:0x402a8d7c> (NoMethodError)
Thanks,
T.