Method attributes in ruby?

Is there any standard way of creating c# like attributes for ruby?

eg in c#

[RequireTransaction]
public void MyMethod()

which can later be examined via reflection and see what attribs are
available on each method.

if there is no standard way, would it be ok to make it like this?

meta :some_method => “BizMethod”
meta :some_method => “WritesData”
meta :some_method => “RequireTrans”
def some_method()

end

by making “meta” a method of Class , wich takes a value key pair
which can later be fetched by another Class method which takes a symbol
like :some_method

eg

attributes = MyType.get_attributes :some_method

or

res = MyType.has_attribute :some_method,“RequireTrans”

Im still too new to Ruby so I feel like mc guyver trying to invent
things and have no clue if they are ok or just stupid :stuck_out_tongue:

//Roger

Roger J. wrote:

Is there any standard way of creating c# like attributes for ruby?

Have you looked at attr_accessor and related methods?

http://www.ruby-doc.org/docs/UsersGuide/rg/accessors.html
http://www.ruby-doc.org/core/classes/Module.html


James B.

“I never dispute another person’s delusions, just their facts.”

  • Len Bullard

Facets has Annotations. (http://facets.rubyforge.org)

But to be clear they are name => value pairs, not just values. You
could do something like this:

ann :some_method, ‘meta’ => [ “BizMethod”, “WritesData”,
“RequireTrans” ]

def some_method()

end

ann.some_method.meta #=> [ “BizMethod”, “WritesData”, “RequireTrans”
]

T.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs