Questions tagged [metaclass]

In object-oriented programming, a metaclass is a class whose instances are classes. Just as an ordinary class defines the behavior of certain objects, a metaclass defines the behavior of certain classes and their instances. Not all object-oriented programming languages support metaclasses.

1179 questions
0
votes
1 answer

Groovy Dynamic Object - How to properly reset properties?

Based on this question I created a Groovy class that will have dynamic properties. class MyDynamic { def propertyMissing( String name, value ) { this.metaClass."$name" = value value } } So far all good, now I can set some non-existent…
user800014
0
votes
2 answers

Are there metaclasses or class reference in D?

Are there any system of classe reference in D? To be more accurate I look for the equivalent of the Delphi TMyClassRef = class of TMyClass; This would be used for a factory (just like in the Object but without using the class name): // ideally void…
babu67
  • 69
  • 7
0
votes
0 answers

Is utilizing simple metaclasses to allow subclasses to overload __init__ without having to call anything additional a good idea?

Some context: I'm creating a very simple component-entity 2d game engine Vast majority of classes will have flat subclass hierarchies Pretty much all base classes don't require any arguments I'm using Python 2 So, the current solution, is to make…
Llamageddon
  • 3,306
  • 4
  • 25
  • 44
0
votes
2 answers

How does Inheritance work in Ruby?

According to Dave Thomas in his talk about the Ruby Object Model, there are no "class methods" in Ruby. There is only difference between whether the receiver of the method is a "class object" or an "instance object". class Dave def InstaceMethod …
zeronone
  • 2,912
  • 25
  • 28
0
votes
1 answer

Django __getitem__ on model: metaclass conflict

In Django, I'd like to implement __getitem__ on a class level (so in the below example, I want to do Alpha['a']). I've found that I need a metaclass for this: just like it this needs to be implemented on a class to make it accessible on the…
Mark
  • 18,730
  • 7
  • 107
  • 130
0
votes
1 answer

Different strategies in python for defining plugins that can also run outside of their defining framework

The scenario is as follows: I'm building a framework that will use external scripts as plugins. People will be able to create "adapters" to the scripts that conform to some interface. These adapters will be used either integrated into the framework…
estani
  • 24,254
  • 2
  • 93
  • 76
0
votes
1 answer

How to metaClass a Groovy method that takes a closure?

How would one metaClass a method that takes an object(s) and a closure? Specifically say, public void eachRow(GString gstring, Closure closure) I'd like to metaClass eachRow() such that it prints the gstring parameter, and ignores the Closure. The…
P. Deters
  • 815
  • 2
  • 9
  • 18
0
votes
2 answers

Reverse mapping class attributes to classes in Python

I have some code in Python where I'll have a bunch of classes, each of which will have an attribute _internal_attribute. I would like to be able to generate a mapping of those attributes to the original class. Essentially I would like to be able to…
wxs
  • 5,617
  • 5
  • 36
  • 51
0
votes
1 answer

Python pattern's RestrictingWrapper with metaclass

I'm trying to create a wrapper that blocks the execution of some methods. The classic solution is to use this pattern: class RestrictingWrapper(object): def __init__(self, w, block): self._w = w self._block = block def…
crispamares
  • 530
  • 4
  • 9
0
votes
0 answers

inheritance from win32com.client class in python

I am using python2.7 with win32com module to access a win32 COM Library. with: import win32com.client app = win32com.client.Dispatch('Word.Application') I get an application object that works fine in python, although I do have only late…
Johannes Maria Frank
  • 2,747
  • 1
  • 29
  • 38
0
votes
1 answer

Weird inheritance with metaclasses

I'm experiencing some really weird problems in Python when trying to inherit from a class with a metaclass. I have this: class NotifierMetaclass(type): def __new__(cls, name, bases, dct): attrs = ((name, value) for name, value in…
cronos2
  • 288
  • 5
  • 13
0
votes
1 answer

Groovy Meta Programming

I want to override a method definition in Grails. I am trying to use Groovy metaprogramming as the class which I want to override belongs to a framework. Below is the original class. class SpringSocialSimpleSignInAdapter implements SignInAdapter { …
Abhijith Prabhakar
  • 1,325
  • 3
  • 12
  • 24
0
votes
1 answer

python apply decorator to every method in a class without inspect

Slightly modifying the answer from Applying python decorators to methods in a class, it is possible to apply a decorator to every method in a class. Is there any way to do this without the inspect module? I've been trying to accomplish this using…
weeb
  • 1,939
  • 4
  • 18
  • 29
0
votes
1 answer

Python Mock type only within module

I am using mock for testing in Python. I am trying to unit test a metaclass which overwrites the __new__ method and then calls type.__new__(cls) internally. I don't want to actually call type.__new__, so I want to mock out type. Of course, I can't…
Travis Parks
  • 8,435
  • 12
  • 52
  • 85
0
votes
1 answer

How to loop through subviews in order to get the text of NSTextViews

I have a NSView which contains several instances of NSTextView. I would like to get the content (string) of each instance. So far, I have this (this code does not compile) : for(NSView *view in [self subviews]) { NSLog(@"class: %@ ", [view…
alecail
  • 3,993
  • 4
  • 33
  • 52