Created
June 10, 2018 08:50
-
-
Save alexroan/2e107b05735c197e579a9e4042f9ea9c 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.24+commit.e67f0147.js&optimize=false&gist=
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
pragma solidity ^0.4.0; | |
//keyword library | |
library IntExtended{ | |
function increment(uint _base) returns(uint){ | |
return _base+1; | |
} | |
function decrement(uint _base) returns(uint){ | |
return _base-1; | |
} | |
function incrementByValue(uint _base, uint _value) returns(uint){ | |
return _base+_value; | |
} | |
function decrementByValue(uint _base, uint _value) returns(uint){ | |
return _base-_value; | |
} | |
} |
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
pragma solidity ^0.4.0; | |
//import statement | |
import "browser/library.sol"; | |
contract testLibrary{ | |
// use <libraryName> for <extendedClass> | |
using IntExtended for uint; | |
function testIncrement(uint _base) returns(uint){ | |
//Because it's a library functon for uint the first parameter | |
//is used as the base object here. | |
//It could be written like this also: | |
//reutrn IntExtended.increment(_base); | |
return _base.increment(); | |
} | |
function testIncrementByValue(uint _base, uint _value) returns(uint){ | |
return _base.incrementByValue(_value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment