-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Berry add reuse of methods for interface-like code reuse (#21500)
- Loading branch information
1 parent
a78169b
commit e56f6a1
Showing
9 changed files
with
88 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# test setting methods as an external class | ||
|
||
class A | ||
var a | ||
def init(a) | ||
self.a = a | ||
end | ||
def f0(x) return self end | ||
def f1(x) return x end | ||
def f2(x) return self.a end | ||
static def ff0(x) return _class end | ||
static def ff1(x) return x end | ||
end | ||
|
||
class B | ||
var b | ||
def init(b) | ||
self.b = b | ||
end | ||
end | ||
|
||
class C : B | ||
var a | ||
def init(a) | ||
self.a = a | ||
end | ||
|
||
def fc0 = A.f0 | ||
def fc1 = A.f1 | ||
def fc2 = A.f2 | ||
static def ffc0 = A.ff0 | ||
static def ffc1 = A.ff1 | ||
end | ||
|
||
c = C(10) | ||
assert(c.fc0(1) == c) | ||
assert(c.fc1(1) == 1) | ||
assert(c.fc2(1) == 10) | ||
assert(c.ffc0(1) == A) | ||
assert(c.ffc1(1) == 1) |