Skip to content

wrong number of arguments (given 1, expected 0) (ArgumentError) #3

Description

@TvL2386

Hi kklimuk,

Thanks for your awesome blog post and this nifty piece of software.
I've been solving this problem countless times as well. I like your implementation! Specifically because you can just toggle it on and off where you like.

The issue I have is minor and I see why it happens. When I memoize a method that does not have arguments, it doesn't work, see example:

require 'ruby_memoized'

class MyExample
  include RubyMemoized

  memoized

  def hello
    puts "hello world"
  end
end

MyExample.new.hello

Output:

$ ruby test_memoization.rb 
Traceback (most recent call last):
	3: from test_memoization.rb:13:in `<main>'
	2: from /home/tom/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ruby_memoized-0.1.3/lib/ruby_memoized.rb:37:in `block in method_added'
	1: from /home/tom/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ruby_memoized-0.1.3/lib/ruby_memoized/memoizer.rb:12:in `call'
test_memoization.rb:8:in `hello': wrong number of arguments (given 1, expected 0) (ArgumentError)

I understand it has to do with your scoped support. It would be great if this could be solved or if another memoization method could be added for this scenario.

Thanks for the big explanation. I can definitely use your code to implement exactly what I need, but maybe ruby_memoized could be even better (imho).

Kind regards,
TvL2386

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions