Skip to content

Commit

Permalink
add examples for methods with arguments to the Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tycooon authored Sep 25, 2019
1 parent fd3f84f commit bce4943
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ a.call { 1 } # => 42
# Will print because passing a block disables memoization
```

Methods with arguments are supported and the memoization will be done based on arguments using an internal hash. So this will work as expected:

```ruby
class A
include Memery

memoize def call(arg1, arg2)
puts "calculating"
arg1 + arg2
end
end

a = A.new
a.call(1, 5) # => 6
a.call(2, 15) # => 17
a.call(1, 5) # => 6
# Text will be printed only twice, once per unique argument list.
```

For class methods:

```ruby
Expand Down

0 comments on commit bce4943

Please sign in to comment.