metamorphism++
See original GitHub issuePS C:\> $PSVersionTable.PSVersion
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 1 0
Hi Guys !!
here an example to demonstrate the new feature
first create base class
PS C:\> class foo {
>> $say = 'hello'
>> [string] sayhello($name) {
>> return '{0} {1}' -f $this.say, $name
>> }
>> }
work well
PS C:\> [foo]::new().sayhello('world')
hello world
create a child class with the same method ‘sayhello’ to overid the base method class
PS C:\> class bar : foo {
>> [string] sayhello($name) {
>> return "power${name}"
>> }
>> }
PS C:\>
work well
PS C:\> [bar]::new().sayhello('shell')
powershell
but sometimes we need to append the result to method “sayhello” in base class and the method “sayhello” in our child class… like in ruby with “super” keyword
this example demonstate the behaviour missing in powershell. in this example i use “super” keyword
PS C:\> class bar : foo {
>> super [string] sayhello($name) {
>> return "power${name}"
>> }
>> }
PS C:\> [bar]::new().sayhello('shell')
hello shell
powershell
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Metamorphism
Metamorphism is the transformation of existing rock (the protolith) to rock with a different mineral composition or texture. Metamorphism takes place at ...
Read more >Types of Metamorphism
In geology this refers to the changes in mineral assemblage and texture that result from subjecting a rock to conditions such pressures, ...
Read more >What are metamorphic rocks? | U.S. Geological Survey
Metamorphic rocks form when rocks are subjected to high heat, high pressure, hot mineral-rich fluids or, more commonly, some combination of these factors....
Read more >Metamorphic Rocks
Metamorphism occurs because rocks undergo changes in temperature and pressure and may be subjected to differential stress and hydrothermal ...
Read more >What are the causes of metamorphism?
Metamorphism is a process that changes pre existing rocks into new forms because of increases in temperature, pressure, and chemically active fluids. The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just to be clear, the first example isn’t an idea, that’s how the PowerShell team decided to implement that functionality (side note: I can kinda see why.
$base
would have been a pain to implement with how the binder works, and since it probably doesn’t matter for DSC it likely wasn’t a big priority). Like that example currently works.$base
would have been nice, but implementing it today may not be feasible without breaking changes.As for
super
, that’s sort of confusing with a return value. It always just adds them together? So if the method returnsint
, the parent returns5
and the child returns5
then the invocation returns10
?Currently you can call a method of the base class like this, but it requires an ugly type cast (see about_Classes):
Output:
I would prefer to call the base class without having to repeat its name and without casting, similar to C#'s
base
keyword: