# Attributes ala java annotations or .Net attributes?

**URL:** <https://www.ruby-forum.com/t/attributes-ala-java-annotations-or-net-attributes/110278>\
**Category:** Ruby\
**Created:** [July 24, 2007, 9:22pm UTC](https://www.ruby-forum.com/t/attributes-ala-java-annotations-or-net-attributes/110278 "2007-07-24T21:22:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [July 24, 2007, 9:22pm UTC](https://www.ruby-forum.com/t/attributes-ala-java-annotations-or-net-attributes/110278/1 "2007-07-24T21:22:29Z")

</div>

Does ruby have attributes ala java annotations or .Net attributes?  
I’ve never seen them in use, hence my wondering.  
Right now I’ve got a pretty big test-suite written in ruby & watir,  
and I’ve got alot of old code in it. It would be nice if I just was  
able to put in something like an [obsolete]/ tag, and have  
it just ignored, or have a warning popup automatically to say “Your’e  
using an obsolete method, get with it!”, or to bip me on the head…

Is there anything like this?

Thanks,  
Kyle

---

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [July 24, 2007, 9:37pm UTC](https://www.ruby-forum.com/t/attributes-ala-java-annotations-or-net-attributes/110278/2 "2007-07-24T21:37:40Z")

</div>

On Wed, Jul 25, 2007, Kyle S. wrote:

> Does ruby have attributes ala java annotations or .Net attributes?  
> I’ve never seen them in use, hence my wondering.  
> Right now I’ve got a pretty big test-suite written in ruby & watir,  
> and I’ve got alot of old code in it. It would be nice if I just was  
> able to put in something like an [obsolete]/ tag, and have  
> it just ignored, or have a warning popup automatically to say “Your’e  
> using an obsolete method, get with it!”, or to bip me on the head…

It’s not exactly what you’re looking for, but there’s a library called  
‘deprecated’ that can be used to achieve that sort of result:

[http://rubyforge.org/projects/deprecated/](http://rubyforge.org/projects/deprecated/)

Ben

---

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [July 24, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/attributes-ala-java-annotations-or-net-attributes/110278/3 "2007-07-24T21:35:27Z")

</div>

On Jul 24, 3:21 pm, “Kyle S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Does ruby have attributes ala java annotations or .Net attributes?  
> I’ve never seen them in use, hence my wondering.  
> Right now I’ve got a pretty big test-suite written in ruby & watir,  
> and I’ve got alot of old code in it. It would be nice if I just was  
> able to put in something like an [obsolete]/ tag, and have  
> it just ignored, or have a warning popup automatically to say “Your’e  
> using an obsolete method, get with it!”, or to bip me on the head…
> 
> Is there anything like this?

Facets has an annotations system, but of course it’s not an built-in  
part of ruby. So it simply supplies a general way to tag you code.  
It’s up to you to actually make it do something. Basic example:

require ‘facets/annotations’

class Y

```
ann :x, :obsolete => true

def x
  ...
end

```

end

Y.ann(:x, :obsolete) #=\> true

So to use that to ignore methods, I suppose you’d want to use  
ObjectSpect.each\_object(Class) to loop through the classes and  
undefine obsolete methods. For warnings, you could wrap them instead.

T.

---

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [July 24, 2007, 9:50pm UTC](https://www.ruby-forum.com/t/attributes-ala-java-annotations-or-net-attributes/110278/4 "2007-07-24T21:50:41Z")

</div>

Hum. OK, thanks you two. Maybe if I’m lucky it’ll end up in ruby 2.0  
😉
