How do you list the currently available objects in the current scope in ruby?

I’m not entirely sure of what you mean by the ‘current objects’. You can iterate over ObjectSpace, as has been mentioned already. But here are a few other methods. local_variables instance_variables global_variables class_variables constants There’s one gotcha. They must be called at the right scopes. So right in IRB, or in an object instance or … Read more

Inspect python class attributes

Below is the hard way. Here’s the easy way. Don’t know why it didn’t occur to me sooner. import inspect def get_user_attributes(cls): boring = dir(type(‘dummy’, (object,), {})) return [item for item in inspect.getmembers(cls) if item[0] not in boring] Here’s a start def get_user_attributes(cls): boring = dir(type(‘dummy’, (object,), {})) attrs = {} bases = reversed(inspect.getmro(cls)) for … Read more

How can I determine the type of a generic field in Java?

Have a look at Obtaining Field Types from the Java Tutorial Trail: The Reflection API. Basically, what you need to do is to get all java.lang.reflect.Field of your class and call Field#getType() on each of them (check edit below). To get all object fields including public, protected, package and private access fields, simply use Class.getDeclaredFields(). … Read more

What does the slash mean when help() is listing method signatures?

It signifies the end of the positional only parameters, parameters you cannot use as keyword parameters. Before Python 3.8, such parameters could only be specified in the C API. It means the key argument to __contains__ can only be passed in by position (range(5).__contains__(3)), not as a keyword argument (range(5).__contains__(key=3)), something you can do with … Read more

Get all methods of an Objective-C class or instance

In addition to Buzzy’s answer, for debugging purposes you may use the -[NSObject _methodDescription] private method. Either in lldb: (lldb) po [[UIApplication sharedApplication] _methodDescription] or in code: @interface NSObject (Private) – (NSString*)_methodDescription; @end // Somewhere in the code: NSLog(@”%@”, [objectToInspect performSelector:@selector(_methodDescription)]); Output will look as following: <__NSArrayM: 0x7f9 ddc4359a0>: in __NSArrayM: Class Methods: + (BOOL) … Read more

How do I get the public methods of a class without inherited methods?

Just pass false for the inherited argument of public_methods: “hello”.public_methods.include?(:dup) # => true “hello”.public_methods(false).include?(:dup) # => false Not an answer to your question, but in case you didn’t know, irb does autocompletion, so it’s easy to get the list of public methods (especially if you know the beginning of the method you are looking for). … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)