mixins

When extending a trait within a trait, what does 'super' refer to?

痞子三分冷 提交于 2019-12-05 11:39:36
问题 I want to to extend a trait within a trait, like this: trait NodeTypes { trait Node { def allNodesHaveThis: Int } } trait ScrumptiousTypes extends NodeTypes { trait Node extends super.Node { def scrumptiousness: Int } } trait YummyTypes extends NodeTypes { trait Node extends super.Node { def yumminess: Int } } object Graph extends NodeTypes with ScrumptiousTypes with YummyTypes { case class Node() extends super.Node { override def allNodesHaveThis = 1 override def scrumptiousness = 2 // error

Is there a way to stub a method of an included module with Rspec?

本秂侑毒 提交于 2019-12-05 08:40:03
问题 I have a module that is included in another module, and they both implement the same method. I would like to stub the method of the included module, something like this: module M def foo :M end end module A class << self include M def foo super end end end describe "trying to stub the included method" do before { allow(M).to receive(:foo).and_return(:bar) } it "should be stubbed when calling M" do expect(M.foo).to eq :bar end it "should be stubbed when calling A" do expect(A.foo).to eq :bar

understanding comparable mixin and enumerable mixin

依然范特西╮ 提交于 2019-12-05 08:18:43
I am a newbie and learning ruby. Would like to have a better understanding of the question asked. I don't understand the use of comparable mixin and enumerable mixin. I mean we don't include these in our class when we need to use them, right? if we want to compare two objects we simply write x > y. Then what is the use of explicitly using them? Great Question Akash! Sometimes it's not "simple" how two objects can be compared! What if you have a Dog class? How do you compare two Dog instances? What should be the comparison based on? Is it enough to compare their name? their breed? their DNA? It

Single Responsibility and Mixins

喜你入骨 提交于 2019-12-05 08:00:59
Given that Mixins generally introduce new behaviour into a class, this generally implies that a class would have more than one behaviour. If a class has a single responsibility this is defined as the class having only one reason for change. So, I can see this from two different perspectives The class only has one reason for change. The module mixed in also has only one reason for change. If the class is changed only the class will need retesting. If the module is changed only the module needs retesting. Hence, SRP is intact. The class now has two reasons for change. If the class is changed,

How to solve “Implementation restriction: trait … accesses protected method … inside a concrete trait method.”

只愿长相守 提交于 2019-12-05 07:50:12
A Java library class I'm using declares protected getPage(): Page { ... } Now I want to make a helper Scala mixin to add features that I often use. I don't want to extend the class, because the Java class has different subclasses I want to extend at different places. The problem is that if I use getPage() in my mixin trait , I get this error: Implementation restriction: trait MyMixin accesses protected method getPage inside a concrete trait method. Is there a solution how to make it work, without affecting my subclasses? And why is there this restriction? So far, I came up with a work-around:

Sass watch is detecting changes but not compiling to css

时光毁灭记忆、已成空白 提交于 2019-12-05 05:36:23
When I run sass --watch app.sass:app.css terminal shows that changes have been detected to sass but won't compile to css. I am using Bourbon so all my .scss and .sass files are imported via mixins. ex. >>> Sass is watching for changes. Press Ctrl-C to stop. >>> Change detected to: css/2-modules/top-nav.scss iamlukem Make sure the file you are saving with an _filename.scss has been properly imported into the mainfile.scss . if you have not imported the _filename.scss it will detect a change but not compile. I had the same issue! In my case, it was caused by having several @imports listed like

Scala compiler cannot infer mix-in type for pattern matching

北城余情 提交于 2019-12-05 05:13:04
I have a use case for algebraic groups over finite permutation sets. Because I would like to use the group for various permutation classes which are otherwise unrelated, I would like to do this as a mix-in trait. Here's an excerpt of my attempt trait Permutation[P <: Permutation[P]] { this: P => def +(that: P): P //final override def equals(that: Any) = ... //final override lazy val hashCode = ... // Lots of other stuff } object Permutation { trait Sum[P <: Permutation[P]] extends Permutation[P] { this: P => val perm1, perm2: P // Lots of other stuff } private object Sum { def unapply[P <:

Alternatives to abstract classes in Ruby?

ε祈祈猫儿з 提交于 2019-12-05 02:11:10
I am new to Ruby. A simple example, what I need: class Animal abstract eat() class Cat < Animal eat(): implementation class Dog < Animal eat(): implementation In other words, the eat() method should be required for all the classes which extend Animal. In JAVA I would just use an abstract class, but after doing some research I found that many people don't use it in Ruby and mixin / modules are recommended instead. However, I don't understand, if modules can do more than just include an addition methods. To be exact, can modules set the requirements for classes which methods they must implement

Groovy Mixins?

大憨熊 提交于 2019-12-05 01:32:46
I'm trying to mix-in a class in my Groovy/Grails app, and I'm using the syntax defined in the docs , but I keep getting an error. I have a domain class that looks like this: class Person { mixin(ImagesMixin) // ... } It compiles fine, but for some reason it won't work. The file containing ImagesMixin is located in my /src/groovy/ directory. I've tried it using Groovy versions 1.5.7 and 1.6-RC1 without any luck. Does anyone know what I'm doing wrong? stacktrace: 2008-12-30 17:58:25.258::WARN: Failed startup of context org.mortbay.jetty.webapp.WebAppContext@562791{/FinalTransmission,/home

Is mixin considered a design pattern?

做~自己de王妃 提交于 2019-12-05 00:54:10
Are mixins considered a design pattern? Structural? They're a language feature. A "pattern" is different from a feature, in that it resolves a set of forces that may influence a situation in contradictory ways. Features, by their presence or absence, tend to create the forces that patterns resolve. Many design patterns (Double Dispatch is a good example) came about to work around language limitations (in this case method dispatching on a single argument). Yes, it is in Ruby. Design Patterns in Ruby Tim Matthews Yes, it is in D. "A design pattern is a general reusable solution to a commonly