subclassing

Failing to subclass builtin String object

喜你入骨 提交于 2019-12-07 07:13:09
问题 I've been experimenting with subclassing the built-in String object in ES2015 using Node 5.3.0. I'm running the code untranspiled using a bunch of harmony flags. Here's the full command: node --harmony --harmony_modules --harmony_destructuring --harmony_rest_parameters --harmony_arrow_functions --harmony_spreadcalls --harmony_object --harmony_default_parameters --harmony_new_target --harmony_reflect --harmony_modules ~/t.js Given that the spec specifically says the String object is made to be

Subclassing Parse's PFUser in Swift

孤街浪徒 提交于 2019-12-07 06:40:08
问题 First off, I know similar questions have been asked before and I've tried following the advice of this stackoverflow answer here to no avail. I also tried adding the basic gist of this as a comment, but I don't have enough rep yet :( Basically I am trying to use PFSubclassing to extend Parse's PFUser model. As such, here's my corresponding code: User.swift: import Foundation import CoreLocation class User : PFUser, PFSubclassing { override init() { super.init() } convenience init(email:

Subclassing NSPredicate to add operator

核能气质少年 提交于 2019-12-07 05:53:50
问题 Cocoa defines predicate classes ( NSPredicate , NSExpression , etc.) which "provide a general means of specifying queries in Cocoa" Predicate Programming . This set of classes describes what I need but with one little short-coming : I'd like additional operators. NSComparisonPredicate already handles 14 operators (NSPredicateOperatorType) but I would like to add, say, temporal operators... or operators to represent things such as: " variable has at least n entries " (binary operator) "

UIWebView and Swift: Detect when a video starts playing

心已入冬 提交于 2019-12-06 09:56:49
问题 In Objective-C, I subscribed to the UIWindowDidBecomeVisibleNotification to know if some view gets above my current view controller, using: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStartedPlaying:) name:UIWindowDidBecomeVisibleNotification object:nil]; So far, so good. Then, in the notification, I could check if the object is not of certain classes (like _UIAlertControllerShimPresenterWindow -alert views- or UITextEffectsWindow -native sharing view-). In

Curiously Recurring Template and Template parameter dependent subclassing issues

好久不见. 提交于 2019-12-06 04:10:21
问题 I am trying to make the following code work template < class __derived, class __object = typename __derived::Object > struct Base { using Derived = __derived; using Object = __object; void function(Object o) { return Derived::function(s); } } //template < class __derived > //struct Base { // using Derived = __derived; // using Object = typename Derived::Object; // void function(Object o) { return Derived::function(s); } //} template < class __object > struct Derived : public Base< Derived< _

How to subclass a subclass of numpy.ndarray

点点圈 提交于 2019-12-06 01:43:22
问题 I'm struggling to subclass my own subclass of numpy.ndarray. I don't really understand what the problem is and would like someone to explain what goes wrong in the following cases and how to do what I'm trying to do. What I'm trying to achieve: I have a subclass of numpy.ndarry that behaves as I want (class A in the code below). I want to subclass A (class B in the code below) so that B contains additional information (name) and methods (the decorated .simple_data method). Case 1: import

Subclassing Parse's PFUser in Swift

☆樱花仙子☆ 提交于 2019-12-05 10:11:39
First off, I know similar questions have been asked before and I've tried following the advice of this stackoverflow answer here to no avail. I also tried adding the basic gist of this as a comment, but I don't have enough rep yet :( Basically I am trying to use PFSubclassing to extend Parse's PFUser model. As such, here's my corresponding code: User.swift: import Foundation import CoreLocation class User : PFUser, PFSubclassing { override init() { super.init() } convenience init(email: String!) { self.init() self.email = email self.username = email } // don't need to call User

Subclassing NSPredicate to add operator

为君一笑 提交于 2019-12-05 08:26:09
Cocoa defines predicate classes ( NSPredicate , NSExpression , etc.) which "provide a general means of specifying queries in Cocoa" Predicate Programming . This set of classes describes what I need but with one little short-coming : I'd like additional operators. NSComparisonPredicate already handles 14 operators ( NSPredicateOperatorType ) but I would like to add, say, temporal operators... or operators to represent things such as: " variable has at least n entries " (binary operator) " variable has value for, at most, n consecutive days " (ternary operator) Obviously, I would need to

Subclassing file by subclassing `io.TextIOWrapper` — but what signature does its constructor have?

有些话、适合烂在心里 提交于 2019-12-05 04:14:11
I'm trying to subclass io.TextIOWrapper following this post , although my aims are different. Starting off with this (NB: motivation ): class MyTextIOFile(io.TextIOWrapper): def read(self, *args): cont = super().read(*args) return cont.replace("\x00", "") I'm trying to open a file using my constructor using In [81]: f = MyTextIOFile("file.csv") but this gives: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-90-343e18b2e32f> in <module>() ----> 1 f = MyTextIOFile("file.csv") AttributeError: 'str' object

How do I ensure that my matplotlib axes are of a custom class?

非 Y 不嫁゛ 提交于 2019-12-05 01:36:30
问题 I have a custom figure class and would like to ensure that all of the axes associated with it, whether created with subplots() or twinx() , etc. have custom behaviors. Right now I accomplish this by binding new methods to each axis after it has been created, e.g. by using import types def my_ax_method(ax, test): print('{0} is doing something new as a {1}.'.format(ax, test)) class MyFigure(matplotlib.figure.Figure): def __init__(self, **kwargs): super(MyFigure, self).__init__(**kwargs) axes_a