Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Singleton/Wren/singleton.wren
Normal file
16
Task/Singleton/Wren/singleton.wren
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
class Singleton {
|
||||
// Returns the singleton. If it hasn't been created, creates it first.
|
||||
static instance { __instance == null ? __instance = Singleton.new_() : __instance }
|
||||
|
||||
// Private constructor.
|
||||
construct new_() {}
|
||||
|
||||
// instance method
|
||||
speak() { System.print("I'm a singleton.") }
|
||||
|
||||
}
|
||||
|
||||
var s1 = Singleton.instance
|
||||
var s2 = Singleton.instance
|
||||
System.print("s1 and s2 are same object = %(Object.same(s1, s2))")
|
||||
s1.speak() // call instance method
|
||||
Loading…
Add table
Add a link
Reference in a new issue