Re: Extend an object with module stored



Andrea Reginato wrote:
> I would like extend dynamically an object with one or more Module that I
> save into an Hash (I now only this way).
>
> -----------------------------
> categorie << Categoria.new('Definizioni Testuali', {:name_module =>
> ListaDefinizioni, })
> categorie << Categoria.new('Definizioni Testuali', {:name_module =>
> ListaDefinizioni, :name_module => ListaDefinizioniEditor})
> -----------------------------
>
> Then I have store this information in a YAML file, but when I dump the
> hash I lost the info about the module.
>
> < snip YAML />
>
> So when I try to extend, nothing to do.
> This code do not give me errors, but it do not extend my object.
>
> -----------------------------
> # @categoria.extension is the hash with the module
> @categoria.estensioni.each_value { |estensione| @denotato.send('extend',
> estensione) }
> -----------------------------
>
> Do you know some tecnique to extend an Object with module stored in YAML
> file?
> Thanks so much to all for the help.

I assume that the module used may vary from object to
object (otherwise it is not necessary to to serialize
it, of course)?

One simple thing you could do would be to store the
*name* of the module instead of the constant. Then,
after loading the YAML, you can use Module#const_get
to obtain the constant again.

> --Reis


E

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


.



Relevant Pages

  • Re: Extend an object with module stored
    ... > I would like extend dynamically an object with one or more Module that I ... > save into an Hash. ... > estensioni: # MY HASH ... subtype, subclass = YAML.read_type_class ...
    (comp.lang.ruby)
  • Re: Question on M1917 American Enfield
    ... Hash: SHA1 ... When I extend it out a bit the discomfort lessens. ...
    (rec.guns)
  • Extend an object with module stored
    ... I would like extend dynamically an object with one or more Module that I ... save into an Hash. ... descrizione: Definizioni Testuali ... estensioni: # MY HASH ...
    (comp.lang.ruby)
  • Re: How is .net generating extra bits in MD5?
    ... > that the length of the derived key is bounded by the length of the hash ... > that the hash algorithm generates, but GetBytes will extend the result ... > extending the result past what PBKDF1 says. ...
    (microsoft.public.dotnet.security)
  • Re: YAML.load_file problems
    ... I thought YAML would be the recommended way ... YAML.load_file returns the contents of the yaml file in a hash or an array ... Trying to access CVSEXE, which ruby thinks is a constant, without having ...
    (comp.lang.ruby)