Top "Metaprogramming" questions

Metaprogramming is the capability to reprogram ones programming environment, as with macros or metaclasses.

java custom annotation: make an attribute optional

I defined my own custom annotation @Target(value={ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface MyCustomAnnotation { Class<?&…

java annotations metaprogramming
How do you pass arguments to define_method?

I would like to pass an argument(s) to a method being defined using define_method, how would I do …

ruby metaprogramming
Objective-C class -> string like: [NSArray className] -> @"NSArray"

I am trying to get a string name of a class from the class object itself. // For instance [NSArray className]; // @"…

objective-c reflection metaprogramming objective-c-runtime
Is it possible to implement dynamic getters/setters in JavaScript?

I am aware of how to create getters and setters for properties whose names one already knows, by doing something …

javascript metaprogramming getter-setter
How can I dynamically create class methods for a class in python

If I define a little python program as class a(): def _func(self): return "asdf" # Not sure what to resplace __…

python class metaprogramming static-methods setattr
Ruby - print the variable name and then its value

What is the best way to write a function (or something DSLish) that will allow me to write this code …

ruby function metaprogramming
How do I convert a Ruby class name to a underscore-delimited symbol?

How can I programmatically turn a class name, FooBar, into a symbol, :foo_bar? e.g. something like this, but …

ruby-on-rails ruby metaprogramming
Ruby Metaprogramming: dynamic instance variable names

Let's say I have the following hash: { :foo => 'bar', :baz => 'qux' } How could I dynamically set the keys …

ruby metaprogramming instance-variables
How do I use define_method to create class methods?

This is useful if you are trying to create class methods metaprogramatically: def self.create_methods(method_name) # To create …

ruby metaprogramming class-method
Dynamic/runtime method creation (code generation) in Python

I need to generate code for a method at runtime. It's important to be able to run arbitrary code and …

python metaprogramming exec