On Tue, Apr 12, 2011 at 4:05 AM, 7stud -- <bbxx789_05ss / yahoo.com> wrote:
> Robert K. wrote in post #992088:
>>
>> Choose to your liking. :-)
>>
>
> Hey Robert K,
>
> I read your factory pattern thread the other day, and I wonder if that
> pattern would apply here? =A0After all, producing several anonymous
> instances of Class is akin to producing instances of various classes.
> Something like this:
>
> class ClassFactory
> =A0def self.using(hash)
> =A0 =A0Class.new do
> =A0 =A0 @options =3D hash
>
> =A0 =A0 =A0 class << self
> =A0 =A0 =A0 =A0 attr_reader :options
> =A0 =A0 =A0 end
>
> =A0 =A0 end
> =A0end
> end

Well, basically you just exchanged Opportunities with ClassFactory
compared to one of my examples.  Actually method #using *is* a factory
method, no matter what class or instance it sits in.

> foo =3D Opportunities.using({one: 1, two: 2, three: 3})
> bar =3D Opportunities.using({four: 4, five: 5, six: 6})

I don't think this can work - at least there's something missing.  Did
you mean to make Opportunities inherit ClassFactory?  But IMHO there
is no point in splitting this up.  Please note also that I made new
classes inherit Opportunities in order for inheritance to work.

> p foo.options
> p bar.options
>
> --output:--
> {:one=3D>1, :two=3D>2, :three=3D>3}
> {:four=3D>4, :five=3D>5, :six=3D>6}
>
>
> Hey Lars Olsson,
>
> Check out the shorter syntax for hashes when your keys are symbols.
>
> foo =3D Opportunities.using({one: 1, two: 2, three: 3})
> bar =3D Opportunities.using({four: 4, five: 5, six: 6})

If we start shortening it, we should do

foo =3D Opportunities.using(one: 1, two: 2, three: 3)

i.e. get rid of the superfluous pair of curly braces. :-)

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/