Skip to content

Commit 33758d9

Browse files
committed
Little refactoring . inverse -. getInverse
Inverse is now a method instead of accessor-bound field for clarity
1 parent cd03104 commit 33758d9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

cachematrix.R

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
## ability to cache results of operations
66

77
CachedOpsMatrix <- setRefClass("CachedOpsMatrix",
8-
fields = list(
9-
value = "matrix",
10-
inverse = function(){
11-
if(is.null(my.inverse))
12-
my.inverse <<- solve(value)
13-
else message("getting cached data")
14-
my.inverse
15-
}),
8+
fields = list(value = "matrix" ),
9+
1610
methods = list(
1711
initialize = function(...){
1812
my.inverse <<- NULL
1913
callSuper(...)
14+
},
15+
16+
getInverse = function(){
17+
"Calculating inverse of matrix. Once it was calculated result is cached and returned in any consecutive call"
18+
if(is.null(my.inverse))
19+
my.inverse <<- solve(value)
20+
else message("getting cached data")
21+
my.inverse
2022
})
2123
)
2224

@@ -32,5 +34,5 @@ makeCacheMatrix <- function(x = matrix()) {
3234
## and returned in any consecutive call
3335

3436
cacheSolve <- function(x, ...) {
35-
x$inverse
37+
x$getInverse()
3638
}

0 commit comments

Comments
 (0)