HI --

On Sat, 6 Sep 2008, Jason Lillywhite wrote:

>
> Thanks. That makes sense. I want to do what is simplest, but it seems
> without cattr things would get worse. Here is what I'm trying to do:
>
> I have one rb file used for inputs:
>
> require 'rubygems'
> require 'activesupport'
>  class Input
>    cattr_reader :y
>    def self.y
>      @y = 2
>    end
>  end
>
> **except I have lots of vars instead of just :y and I'm assigning them
> values here.
>
> Then I go to a new rb file and do this:
>
> require 'firstfile.rb'
> class NewClass
>  def do_something
>    Input.y * 2.3
>  end
> end
>
> new = NewClass.new
> p new.do_something
>
> **The fact that I need to say "Input.y" seems very bulky. Is there a
> better way to do this? Plus, if I get away from class vars, it will get
> bulkier. any ideas?

You're not actually using any class variables in your example. If you
delete the cattr_reader line, the code still runs. You're writing a
"reader" method (Input.y) by hand, and it's using an instance
variable, not a class variable (an instance variable belonging to the
class Input itself).


David

-- 
Rails training from David A. Black and Ruby Power and Light:
   Intro to Ruby on Rails  January 12-15   Fort Lauderdale, FL
   Advancing with Rails    January 19-22   Fort Lauderdale, FL *
   * Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!