mixins

Mixin and interface implementation

一世执手 提交于 2019-12-10 21:07:22
问题 According to http://www.thinkbottomup.com.au/site/blog/C%20%20_Mixins_-_Reuse_through_inheritance_is_good But hang on a minute, none of this helps us plug into our Task Manager framework as the classes do not implement the ITask interface. This is where one final Mixin helps - a Mixin which introduces the ITask interface into the inheritance hierarchy, acting as an adapter between some type T and the ITask interface: template< class T > class TaskAdapter : public ITask, public T { public:

RSpec - mock (or stub) overriden mixin method

时光怂恿深爱的人放手 提交于 2019-12-10 21:05:06
问题 I have situaltion like this: module Something def my_method return :some_symbol end end class MyClass include Something def my_method if xxx? :other_symbol else super end end end Now the problem is with testing - I would like to ensure that super method got called from overriden method and stub it so that I can test other parts of method. How can I accomplish that using RSpec mocks? 回答1: Ensuring that super gets called sounds a lot like testing the implementation, not the behaviour, and

how to using jade Mixin in Javascript?

删除回忆录丶 提交于 2019-12-10 21:04:58
问题 In jade, i'm make test mixins mixin test(testName) #test span Test String But i want using this in javascript (this is declare in jade file) script(type='text/javascript'). $( document ).on( "click", "#addBtn", function() { $("#list").append( I WANT USE MIXIN THIS PLACE ); }); How to use mixin in javascript? 回答1: You can't use a Jade mixin in a JavaScript file because Jade templates are rendered on server side. 来源: https://stackoverflow.com/questions/24068728/how-to-using-jade-mixin-in

Scala mixin to class instance

南笙酒味 提交于 2019-12-10 19:59:59
问题 Is it possible in Scala to make some mixin to class instance? Eg: I have some MyClass instance var x = new MyClass and I want to extend it on some method or trait without copying it. [Edit:] I'm looking the way to extend x after it has been instantiated. So, for example in a function method, which gets x as a parameter. [What is behind] I've just wonder if there is some magic with implicit objects and Manifest to achieve the typeclass pattern without explicit call implicit object (like in

Adding vendor prefixes with LESS mixin

爱⌒轻易说出口 提交于 2019-12-10 19:12:05
问题 I'm getting a Syntax Error for this mix-in: .vendors(@statement){ @statement; -moz-@statement; -webkit-@statement; } Any way to do this, or do mixin variables have to be on the right side of a : ? 回答1: Since Less v2 you can use the autoprefix plugin to prefix your properties, which seems to be a better alternative. The autoprefix plugin add browser prefixes leveraging the autoprefixer postprocessor. For client side compiling (in the browser) you can use -prefixfree. As already mentioned by

LESS - Assign mixin to variable and reuse

房东的猫 提交于 2019-12-10 16:48:37
问题 Given this LESS mixin: #gradient { .vertical (@startColor: #555, @endColor: #333) { background-color: @endColor; background-repeat: repeat-x; background-image: -khtml-gradient(linear, left top, left bottom, from(@startColor), to(@endColor)); /* Konqueror */ background-image: -moz-linear-gradient(@startColor, @endColor); /* FF 3.6+ */ background-image: -ms-linear-gradient(@startColor, @endColor); /* IE10 */ background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%,

Mixing roles into callables

帅比萌擦擦* 提交于 2019-12-10 14:49:59
问题 Theoretically, you can mix in a role into an object in runtime. So I am trying to do this with a function: my &random-f = -> $arg { "Just $arg" }; say random-f("boo"); role Argable { method argh() { self.CALL-ME( "argh" ); } } &random-f does Argable; say random-f.argh; Within the role, I use self to refer to the already defined function, and CALL-ME to actually call the function within the role. However, this results in the following error: Too few positionals passed; expected 1 argument but

“uninitialized constant” when included test helper module

强颜欢笑 提交于 2019-12-10 13:42:41
问题 I am getting an uninitialized constant error when trying to include a helper module into a test. I have the following files in my rails test directory functional> admin> school_controller_test.rb functional> controller_helper.rb The class/modules bodies are as follows: module ControllerHelper def check_sort_order (items, column, direction) ... end end class Admin::SchoolsControllerTest < ActionController::TestCase include ::ControllerHelper test "should sort by columns" do check_sort_order

Assigning a value to the attribute of a mixed-in role

不打扰是莪最后的温柔 提交于 2019-12-10 13:07:01
问题 I'm trying to work an example that uses the Enumeration role in Perl 6 (as part of fixing doc issue Enumeration role is not documented). I came up with this simple example: class DNA does Enumeration { my $DNAindex = 0; my %pairings = %( A => "T", T => "A", C => "G", G => "T" ); method new( $base-pair where "A" | "C" | "G" | "T" ) { self.bless( key => $base-pair, value => %pairings{$base-pair}, index => 33); } multi method gist(::?CLASS:D:) { return "$!key -> $!value with $!index"; } } for <A

Accessors Composition in ES6 Classes

人走茶凉 提交于 2019-12-10 12:00:47
问题 Let's say I have a Thing class which I want to be both Hideable and Openable . Using a similar approach to Douglas Crockford's object creation through composition, I have been able to "inherit" from multiple classes. This approach does not work with accessors (getter/setters). I need to use classes as it's a requirement. I'm also finding that I am duplicating functionality from class to class, but I don't want these to inherit from a base class. Any ideas? The progress I have made so far is