p1 = new point # no () after class name (point)
class point
# here the class region
x = 10 # default value
y = 20 # default value
x = 30 # default value
p1 = new point(100,200,300) # Now we pass parameters
class point
x=10 y=20 z=30
func init nX,nY,nZ
x=nX y=nY z=nZ
class point
self.x = 10 # if x is global, Here using self.x avoid the global variable
self.y = 20 # so using self is just a protection from global variables
self.z = 30
func draw
# some code to draw the point using RingAllegro, RingLibSDL or RingQt
# Another code (just for test)
x = 100 # Try to use x, search in local variables then object attributes
self.x = 100 # Try to use x, search in attributes directly
this.x = 200 # In this location this.x is the same as self.x
# Special case
oSomeObject = new AnotherClass # here we create object from another class
oSomeObject { # here we access the new object using braces
self.x = 100 # self.x = oSomeObject.x
this.x = 100 # this.x will access object from the Point class
# using this we escape from braces {}
# This is smart and know the current class
# But Self just access the active object
}
BertBlock = new Block( index="2", timestamp="20/07/2017", data="Exodus" )
BertBlock = new Block() { index="2" timestamp="20/07/2017" data="Exodus" }
func init()
{
this.index = "0"
this.timestamp = "2001/01/01"
this.data = "funcInit-GenesisCoin"
this.previousHash = "1234"
this.hash = calculateHash()
}
func init()
{
this.index = "0"
this.timestamp = "2001/01/01"
this.data = "funcInit-GenesisCoin"
this.previousHash = "1234"
this.hash = calculateHash()
return self
}
Ring seems more complicated in how it passes args using () and {} etc
func init p1,p2,p3
#here we can use p1,p2,p3
new myclass(p1Value,p2Value,p3Value)
### Block() with args provides.
BertBlock = new Block("2", "20/07/2017", "Exodus" )
### <<< Line 24 Error (R20) : Calling function with extra number of parameters!
func init()
### Block() with args provides. No comma separators BertBlock = new Block("2" "20/07/2017" "Exodus" )
### <<< Line (29) Error (C8) : Parentheses ')' is missing
### Block(){} with args provides. No comma separatorsBertBlock = new Block() { index="2", timestamp="20/07/2017", data="Exodus" }
### <<< Line (39) Error (C18) : Missing closing brace for the block opened!
BertBlock = new Block() { index="2" timestamp="20/07/2017" data="Exodus" }
BitCoin-BlockChain.ring
How to use Class, Variables, and Functions in an OOP's manner
Attached is the latest complete version of the program
it also checked if the BlockChain is Valid or if it has been tampered with
==================
OUTPUT
================= TEST if VALID CHAIN ===================
Len-BertChain.chain 4
Test isChainValid: VALID
Before Change: Block.data
index: 2
timestamp: 22/1/2017
data: Amount-8
previoushash: 0097e3096ad5638d419013a8f97168ea17838bc2cc723628445713deb7cc345b
hash: 00d482d5c02b468c5a966dfcf3cacebca98613f4a280936257d16e93f4fddbcc
nonce: 425.000000
After Change: Block.data
index: 2
timestamp: 22/1/2017
data: Amount-100
previoushash: 0097e3096ad5638d419013a8f97168ea17838bc2cc723628445713deb7cc345b
hash: 00d482d5c02b468c5a966dfcf3cacebca98613f4a280936257d16e93f4fddbcc
nonce: 425.000000
Test isChainValid: INVALID
===============================