Copying parameters to singleton class

Robert K. wrote in post #992232:

Something like this:
  end
end
end

Well, basically you just exchanged Opportunities with ClassFactory
compared to one of my examples.

Yes, that's true.

Did
you mean to make Opportunities inherit ClassFactory?

Yes. I think you must have posted in the middle of one of my edits
because Opportunities does inherit from 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.

Yes, I noticed that, but I don't think that is a requirement.

If we start shortening it, we should do

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

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

Good catch.

···

On Tue, Apr 12, 2011 at 4:05 AM, 7stud -- <bbxx789_05ss@yahoo.com> > wrote:

--
Posted via http://www.ruby-forum.com/\.

Lars Olsson wrote in post #992715:

> old_options[key] = new_options[key]

     old_options.has_key?(key)
    end.freeze
   end
  end

--
Posted viahttp://www.ruby-forum.com/.

Hi!

Even though I agress that using the same name for both the local
parameter and a method with the same name might be a bad idea, my code
still works without any problem. If I redefine self using to:

There's working code, and there's clear code. The goal: working code
that is clear!

Hmmm...why can you merge() but not directly assign to
individual keys when a hash is frozen?

Duh. Because merge() produces a new hash--it doesn't change the frozen
hash.

···

On 14 Apr, 03:09, 7stud -- <bbxx789_0...@yahoo.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

7stud -- wrote in post #992354:

The syntax is a little simpler doing this:

    class << singleton
      attr_reader :options #(self.)attr_reader, where self=singleton
    end

...actually, class << singleton puts us in the singleton class of
singleton, so that should say "self = singleton class of singleton".

···

--
Posted via http://www.ruby-forum.com/\.