Questions tagged [introspection]

A capability of some object-oriented programming languages to determine the type of an object at runtime.

Some OOP languages providing Type Introspection ability : Ruby, Objective-C, C++, Java, PHP, Perl, Python, Object Pascal, Actionscript (as3)

The introspection is done differently, depending on the form of program, it is performed upon: inspecting a source code or compiled byte-code is called compile-time introspection, while inspecting properties of running code is a run-time introspection.

For example, Java supports both types of introspection: users of run-time introspection typically perform it via , while compile-time introspection can be implemented with tools or .

http://en.wikipedia.org/wiki/Type_introspection

1021 questions
27
votes
4 answers

Get a view controller's class name as string

If I have a UIViewController subclass, how can I get the class name as string? I've tried doing [vc class], but this returns a Class object, not an NSString.
xonegirlz
  • 8,889
  • 19
  • 69
  • 127
26
votes
3 answers

Iterate the classes defined in a module imported dynamically

I have a module from a child package that is imported dynamically; how can I iterate over the classes that it contains? I have been importing the module and listing the names like this: package = current_module.__name__ package =…
Will
  • 73,905
  • 40
  • 169
  • 246
26
votes
4 answers

How can I determine if a Perl function exists at runtime?

I'm working on a test framework in Perl. As part of the tests, I may need to add precondition or postcondition checks for any given test, but not necessarily for all of them. What I've got so far is something like: eval…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
26
votes
10 answers

Listing defined functions in Bash

I'm trying to write some code in bash which uses introspection to select the appropriate function to call. Determining the candidates requires knowing which functions are defined. It's easy to list defined variables in bash using only parameter…
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
25
votes
10 answers

Get property name as a string

I need a way to pass a property and get the name assigned to it. Any suggestions? @property (nonatomic, retain) MyObject *crazyObject; NSString *str = SOME_WAY_TO_GET_PROPERTY_NAME(crazyObject); // Above method should return @"crazyObject"
aryaxt
  • 76,198
  • 92
  • 293
  • 442
25
votes
5 answers

Any way to determine which object called a method?

I'm hoping that Ruby's message-passing infrastructure means there might be some clever trick for this. How do I determine the calling object -- which object called the method I'm currently in?
Joseph Weissman
  • 5,697
  • 5
  • 46
  • 75
25
votes
4 answers

How do I introspect things in Ruby?

For instance, in Python, I can do things like this if I want to get all attributes on an object: >>> import sys >>> dir(sys) ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__',…
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
25
votes
4 answers

Python logging using a decorator

This is the first example we meet when we face with decorators. But I'm not able to realize what exactly I would like. A simple decorator named LOG. It should work like this: @LOG def f(a, b=2, *c, **d): pass And the result should be something…
Luca
  • 251
  • 1
  • 3
  • 4
24
votes
5 answers

How Do I Perform Introspection on an Object in Python 2.x?

I'm using Python 2.x and I have an object I'm summoning from the aether; the documentation on it is not particularly clear. I would like to be able to get a list of properties for that object and the type of each property. Similarly, I'd like to…
Metahyperbolic
24
votes
2 answers

Checking up on a `concurrent.futures.ThreadPoolExecutor`

I've got a live concurrent.futures.ThreadPoolExecutor. I want to check its status. I want to know how many threads there are, how many are handling tasks and which tasks, how many are free, and which tasks are in the queue. How can I find out these…
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
24
votes
6 answers

Python: How to retrieve class information from a 'frame' object?

Is it possible to retrieve any class information from a frame object? I know how to get the file (frame.f_code.co_filename), function (frame.f_code.co_name) and line number (frame.f_lineno), but would like to be able to also get the name of the…
Kevin Little
  • 12,436
  • 5
  • 39
  • 47
24
votes
4 answers

Does Scala have introspection capable of something similar to Python's dir()?

Yes, I know it's considered lazy by the non-Pythonistas. The reason I ask is that documentation is still woefully lacking in many Scala libraries (e.g. Scala-dbc, but that's not all I'm looking at), and if I could see the attributes of an…
JohnMetta
  • 18,782
  • 5
  • 31
  • 57
24
votes
3 answers

How do I list all fields of an object in Objective-C?

If I have a class, how can I list all its instance variable names? eg: @interface MyClass : NSObject { int myInt; NSString* myString; NSMutableArray* myArray; } I would like to get "myInt", "myString", and "myArray". Is there some way…
Paul Green
24
votes
6 answers

Find functions explicitly defined in a module (python)

Ok I know you can use the dir() method to list everything in a module, but is there any way to see only the functions that are defined in that module? For example, assume my module looks like this: from datetime import date, datetime def test(): …
Cory
  • 22,772
  • 19
  • 94
  • 91
23
votes
6 answers

Haskell: Function to determine the arity of functions?

Is it possible to write a function arity :: a -> Integer to determine the arity of arbitrary functions, such that > arity map 2 > arity foldr 3 > arity id 1 > arity "hello" 0 ?
Frank S. Thomas
  • 4,725
  • 2
  • 28
  • 47