Re: Extend an object with module stored
- From: Eero Saynatkari <ruby-forum-reg@xxxxxxxxxxxxxx>
- Date: Wed, 1 Feb 2006 04:20:03 +0900
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/.
.
- References:
- Extend an object with module stored
- From: Andrea Reginato
- Extend an object with module stored
- Prev by Date: XML, WebService and Character Encoding issue
- Next by Date: Re: Syntax
- Previous by thread: YAML-ing classes and modules in 1.8.4 -- Was: Re: Extend an object with module stored
- Next by thread: Beginner question on classes on different files
- Index(es):
Relevant Pages
|