Sean Ross wrote:

>class C
>    attr_reader :a
>    def C.new
>        # initialization
>        # return new instance of C
>    end
>end
>
>  
>

Well, keep in mind that in C.new, @a is not accessible.  Thus, unless 
'a' is a writable attribute, the C.new method cannot directly write to 
it (thus the existence of the initialize method, to do instance-specific 
initialization).

However, with eval magic, you can do it:

  def C.new( a )
    obj = allocate
    obj.instance_eval { @a = a }
    obj
  end

It just feels kind of klunky to me (and an invasion of C's privacy) to 
use instance_eval like that...

- Jamis

-- 
Jamis Buck
jgb3 / email.byu.edu

ruby -h | ruby -e 'a=[];readlines.join.scan(/-(.)\[e|Kk(\S*)|le.l(..)e|#!(\S*)/) {|r| a << r.compact.first };puts "\n>#{a.join(%q/ /)}<\n\n"'