Last active
May 16, 2018 16:33
-
-
Save jigar23/c95930e753f75994112b9dbe9addcf97 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.23+commit.124ca40d.js&optimize=false&gist=
This file contains hidden or 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
pragma solidity ^0.4.0; | |
// using Libraries | |
library IntExtended { | |
function Increment(uint self) returns (uint) { | |
return self + 1; | |
} | |
function Decrement(uint _self) returns (uint) { | |
return _self - 1; | |
} | |
function IncrementByValue(uint _self, uint _value) returns (uint) { | |
return _self + _value; | |
} | |
function DecrementByValue(uint _self, uint _value) returns (uint) { | |
return _self - _value; | |
} | |
} |
This file contains hidden or 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
pragma solidity ^0.4.0; | |
import "browser/library.sol"; | |
// can also import from github | |
//import "github.com/jigar/solidity/library.sol" | |
contract TestLibrary { | |
// can also use | |
// using IntExtended for *; | |
// * will work for all types including string | |
using IntExtended for uint; | |
function testIncrement(uint _base) returns (uint) { | |
// Can also use static calling | |
return IntExtended.Increment(_base); | |
// return _base.Increment(); | |
} | |
function testDecrement(uint _base) returns (uint) { | |
return _base.Decrement(); | |
} | |
function testIncrementByValue(uint _base, uint _value) returns (uint) { | |
return _base.IncrementByValue(_value); | |
} | |
function testDecrementByValue(uint _base, uint _value) returns (uint) { | |
return _base.DecrementByValue(_value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment