mixins

Scala traits mixin order and super call

谁都会走 提交于 2019-12-22 04:45:07
问题 I have this code: trait base{ def msg: Unit= { println{"base"} } } trait foo extends base { abstract override def msg: Unit ={ super.msg println("foo") } } class base2{ def msg:Unit = { println{"base 2"} } } class test extends base2 with foo{ override def msg: Unit ={ super.msg println("done") } } If I call (new test).msg , this prints out things like: base, foo, done However, if I change the base trait to: trait base{ def msg: Unit } it prints out things like: base 2, foo, done I understand

Using LESS mixin to set variable multiple times but getting wrong results

99封情书 提交于 2019-12-21 23:25:13
问题 At the front, I started with less today... So any advice how to do that better is welcome! I have following .less file: .test(@target;@context) { @em: (@target / @context) * 1em; } .custom-field { position: relative; .test(30;16); padding-bottom: @em; .test(30;16); margin-bottom: @em; .test(320;16); max-width: @em; } I expect that padding-bottom and margin-bottom getting the value 1.875 and max-width: 20. But thats the output: .custom-field { position: relative; padding-bottom: 1.875em;

Mixin or Trait implementation in AS3?

天涯浪子 提交于 2019-12-21 17:19:45
问题 I'm looking for ideas on how to implement a Mixin/Trait style system in AS3. I want to be able to compose a number of classes together into a single object. Of course this is not a language level feature of AS3, but I'm hoping that there is maybe some way to do this using prototype based techniques or maybe some bytecode hacking that I believe AsMock uses to implement it's functionality. An existing Java example is Qi4J where the user define interfaces that the Qi4j framework implements based

In Ruby or Rails, why is “include” sometimes inside the class and sometimes outside the class?

隐身守侯 提交于 2019-12-21 07:29:47
问题 I thought class ApplicationController < ActionController::Base include Foo is to add a "mixin" -- so that all methods in the Foo module are treated as methods of the ApplicationController. But now I see code that is include Bar class ApplicationController < ActionController::Base include Foo So why is it outside of ApplicationController ? How is that different from the more common use of putting it inside of ApplicationController ? 回答1: Yes, include Foo inside a class adds Foo to that class's

In Ruby or Rails, why is “include” sometimes inside the class and sometimes outside the class?

感情迁移 提交于 2019-12-21 07:29:06
问题 I thought class ApplicationController < ActionController::Base include Foo is to add a "mixin" -- so that all methods in the Foo module are treated as methods of the ApplicationController. But now I see code that is include Bar class ApplicationController < ActionController::Base include Foo So why is it outside of ApplicationController ? How is that different from the more common use of putting it inside of ApplicationController ? 回答1: Yes, include Foo inside a class adds Foo to that class's

LESS css set dynamic background image with mixin

喜欢而已 提交于 2019-12-20 17:39:33
问题 I am using LESS CSS . I am currently using Mixins with variables. Something like this works okay : .border-radius (@radius) { border-radius: @radius; } #header { .border-radius(4px); } This is not : .bg-img(@img) { background-image:url(@img); } #logo { .bg-img("../images/logo.jpg"); } i have tried combinations of using ' & " in the background-image:url ('') & ("") but then it tries to get the image as images/@img instead of the image name. other wise it gives me an error of Cannot call method

Refactoring ActiveRecord models with a base class versus a base module

南笙酒味 提交于 2019-12-20 10:36:32
问题 Class A and B are identical: class A < ActiveRecord::Base def foo puts "foo" end end class B < ActiveRecord::Base def foo puts "foo" end end What's the difference between refactoring like this with a base class : class Base < ActiveRecord::Base def foo puts "foo" end end class A < Base end class B < Base end versus like this using a base module : module Base def foo puts "foo" end end class A < ActiveRecord::Base include Base end class B < ActiveRecord::Base include Base end Is one way

What is the difference between an Abstract Class and a Mixin?

早过忘川 提交于 2019-12-20 10:33:01
问题 I just found an article on a framework in Java that apparently allows it to support Mixins and something called Composite Oriented Programming (which for all I know might even be the same thing...) I've also heard of/worked with AOP, and I'm not sure how it differs from this either... 回答1: At a language-agnostic level, a mixin just adds functionality to a class, and is more for programmer convenience and to avoid code duplication. An abstract (base) class forms an is-a relationship and allows

CSS rules output by SASS mixin being ignored

不想你离开。 提交于 2019-12-20 06:51:08
问题 A SASS mixin which produces some CSS rules is being ignored. Chrome Dev Tools is showing the rules registered but crossed out and I cannot figure out why. I initially thought there was a conflict of specificity but there are no conflicting rules. Here is the SASS: span.icon { display: inline-block; background-image: url('images/sprite.png'); background-repeat: no-repeat; &.telephone { @include sprite('19px', '25px', '-300px 0'); } } Here is the mixin: @mixin sprite($width, $height, $bg

LESS: associative array in LOOP

杀马特。学长 韩版系。学妹 提交于 2019-12-20 04:32:26
问题 I need to add an icon to a page, depending by its content. In other words, if a page contain an image, a gallery, a video... I'll add an icon indicating its nature. To do this, I add CSS class to body tag and use descendant selector to add icons in the proper position. Obviously this task results in a lot of repeating code in CSS, so I would like to generate it with a LESS Loop. Here my actual attempt ( icons are icon-fonts ): @icons:"\e926", "\e90e", "\e914"; .icons-loop(@i; @ico) when (@i <