Two correct ways to use for/in
in JavaScript:
for (var i in a) {
if (!a.hasOwnProperty(i)) continue;
// loop body
}
for (var i in a) {
public class Main { | |
public static void main(String[] args) { | |
A a = new A(); | |
B b = null; | |
try { | |
b = new B(a); | |
} catch (Exception e) {} | |
System.out.println(a.b); | |
System.out.println(b); |
class AbstractViewModel { | |
def model | |
def propertyMissing(String name) { | |
model.get(name) | |
} | |
def methodMissing(String name, args) { | |
model.invokeMethod(name, args) | |
} |
class Del { | |
def del() { println "Del.del" } | |
} | |
class Super { | |
def sup() { println "Super.sup" } | |
} | |
class Sub extends Super { | |
@Delegate Del del = new Del() |
grails test-app SrpMapSpec --stacktrace --verbose | |
| Packaging Grails application..... | |
| Packaging Grails application..... | |
| Packaging Grails application..... | |
| Packaging Grails application..... | |
| Running Grails application | |
May 13, 2013 10:44:55 AM org.apache.coyote.AbstractProtocol init | |
INFO: Initializing ProtocolHandler ["http-bio-7080"] | |
May 13, 2013 10:44:55 AM org.apache.catalina.core.StandardService startInternal |
class MixinFoo { | |
def foo() { println "foo" } | |
} | |
@Mixin(MixinFoo) | |
class MixinBar { | |
def bar() { println "bar" } | |
} | |
Two correct ways to use for/in
in JavaScript:
for (var i in a) {
if (!a.hasOwnProperty(i)) continue;
// loop body
}
for (var i in a) {
includeTargets << grailsScript("_GrailsInit") | |
def createTestCommand(reportPath, serverPort, chromeDriverPort, testPhaseAndType) { | |
"grails -Dgrails.project.test.reports.dir=${reportPath} -Dserver.port=${serverPort} " + | |
"-Dchrome-driver.port=${chromeDriverPort} test-app ${testPhaseAndType}" | |
} | |
target(main: 'Run lego and functional tests in parallel') { | |
def threads = [] | |
def reportsBaseDir = 'para-reports' |
.button-group { | |
margin: 100px auto; | |
width: 290px; | |
height: 50px; | |
border-radius: 4px; | |
background-image: -webkit-linear-gradient(top, #f1f6fa, #dee7f0); | |
box-shadow: | |
0 0 2px 0 rgba(64, 100, 138, 0.5), | |
0 4px 10px 0 #3b5c7f; |
class Point
attr_accessor :x
attr_accessor :y
def initialize(*args)
init_methd_name = "_init_#{args.size}"
send(init_methd_name, *args)
end
I was working on a small Ruby program today and I repeatedy needed to write classes that can accept a variable number of arguments in their constructors.
This is the initial solution I came up with:
class MyClass
def initialize(*args)
init_methd_name = "_init_#{args.size}"