Hi Greg,

Well the methods you can call *as* a class is being defined are
*class* methods.  initialize_colors is an instance method, as it
should be since it's setting instance variables.

It seems to me that you want to call initialize_colors not as the
class is being defined but as instances are being created.  And
therefore the call to initialize_colors should be inside Square's
initialize method.

Eric

====

Are you interested in on-site Ruby training that's been highly
reviewed by former students?  http://LearnRuby.com

On Nov 22, 12:58 pm, Greg Willits <li... / gregwillits.ws> wrote:
> Can't see the tree for the forest.
>
> Playing with how to integrate modules, classes, subclasses, and create
> instance methods and class methods from modules.
>
> In this play code below, I want to use initialize_colors in either the
> class Shape or Square as a class method.
>
> At this point I'm sure I'm missing a very simple syntax rule explained
> very clearly in the books, but the code as is complains about
> initialize_colors as being undefined, and I'm just not recognizing what
> I am missing.
>
> module Color
>
>   def initialize_colors
>     @fill_color   = 'ffffff'
>     @border_color   = '000000'
>   end
>
>   def set_fill_rgb(color)
>     if color == 'white'
>       @fill_color = 'ffffff'
>     elsif color == 'red'
>       @fill_color = 'ff0000'
>     elsif color == 'blue'
>       @fill_color = '0000ff'
>     elsif color == 'black'
>       @fill_color = '000000'
>     end
>   end
> end
>
> class Shape
>
>   include Color
>
>   attr_reader :fill_color, :border_color
>
>   def initialize
>     @fill_color   = String.new
>     @border_color   = String.new
>   end
> end
>
> class Square < Shape
>
>   initialize_colors
>
> end
>
> sq = Square.new
> puts sq.fill_color
> sq.set_fill_rgb('red')
> puts sq.fill_color
> --
> Posted viahttp://www.ruby-forum.com/.