1 Jun 2003 01:04
[RCR] attr_reader :foo?
Joel VanderWerf <vjoel <at> PATH.Berkeley.EDU>
2003-05-31 23:04:16 GMT
2003-05-31 23:04:16 GMT
Would it make sense for attr_reader and friends to associate :foo? with
the attribute " <at> foo" ?
Consider the following code:
class C
attr_accessor :foo?
def initialize
<at> foo = true
end
end
c = C.new
p c.foo? # ==> false
c.send("foo?=", true)
p c.foo? # ==> true
p c.instance_variables # [" <at> foo"]
You can call the reader. You have to bend over backwards to call the
writer. You cannot access the attribute itself from within method
definitions. You can't even see that it exists using #instance_variables.
Since the use of attr_accessor construct is so pointless in this case,
why not change the semantics:
"attr_reader :foo?" defines a method #foo? which gets
the value of <at> foo,
"attr_writer :foo?" defines a method #foo= which sets
(Continue reading)
>
> A feature. This is added to accomplish better debugger tracing.
> The call timing may be changed in the future.
>
> matz.
>
< abbreviated ri 1.8 description>
------------------------------------------------- Kernel::set_trace_func
set_trace_func( aProc ) -> aProc
set_trace_func( nil ) -> nil
------------------------------------------------------------------------
Events are: c-call, c-return, call , class, end,
line (execute code on a new line), raise and return.
</>
puts "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
set_trace_func proc {| ev, fi, li, oi, bi, cl |
printf("(%8s) %s:%-2d (%10s) %s %8s\n",
ev, fi[-11,11], li, oi.inspect, bi.to_s, cl) if ev == 'line'
}
##- line 7
a =
RSS Feed