* Zach Dennis <zdennis / mktec.com> [051031 14:36]:

> Ok, still wrapping my head around this... Is the following a correct assumption?
> 
> You would use:
>     class MyObject
>   	ann :type => :browsable
>          ...
>     end
> 
> Over something like?
>     class CandyBar
>         attr_reader :browseable?
>         ...
>     end

I don't think this example is very useful to demonstrate annotations. In
fact in this case annotations don't seem to be more usefull than a simple
attribute. Allow me to give one last example where annotations might
proove to be more usefull:

Let's say you need to write your own magic persistance layer which you
want to use to persist parts of your objects in the ObjectSpace.

So first, you can annotate the classes you need to persist with a tag
alla "persistable". Now let's assume you want to control, which of the
instance variables need to be persisted and which not. So you annotate
the required attributes with another tag like "persist_me".

Now your persistance code can search for objects that need to be
persisted and can decide what to do with their attributes. Thanks to
reflection and annotations you now have all the information at your hand
to do the job.

Of course there are other ways[tm] to achieve this goal but in my opion
annotations are very elegant and still simpel to use.


Cheers,

Steph.