On Sun, 11 Mar 2007, Thomas Hafner wrote:

> Hello,
>
> is there a way to get an object, if only its object-specific class is
> given? For instance, given
>
>  c = class << Hash[:a, 5]
>    def mult(x)
>      self[:a] * x
>    end
>    self
>  end
>
> can I retrieve the hash object via evaluation of c?

   harp:~ > cat a.rb
   c = class << Hash[:a, 5]
     def mult(x)
       self[:a] * x
     end
     self
   end

   p c.instance_eval{ self }


   harp:~ > ruby a.rb
   #<Class:#<Hash:0xb75cfd18>>

if you are doing much of this sort of thing check out the prototype lib


harp:~ > cat a.rb
require 'rubygems'
require 'prototype'

c = Object.prototype(Hash) do
   def mult(x)
     self[:a] * x
   end

   def initialize
     self[:a] = 5
   end
end

p c



harp:~ > ruby a.rb
{:a=>5}



-a
-- 
be kind whenever possible... it is always possible.
- the dalai lama