Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TvL2386 opened this issue May 18, 2020 · 6 comments
Open

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

TvL2386 opened this issue May 18, 2020 · 6 comments

Comments

@TvL2386
Copy link

TvL2386 commented May 18, 2020

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

@TvL2386
Copy link
Author

TvL2386 commented May 18, 2020

it seems you can check whether a method requires arguments with:

def test; end
method(:test).parameters

@TvL2386
Copy link
Author

TvL2386 commented May 18, 2020

Ok, I've modified your code to support it. I have no experience with rspec and building a test will probably take me more work, but I've got something that works. Please check if you like it and whether it's usefull for you.

@TvL2386
Copy link
Author

TvL2386 commented May 18, 2020

Please see my pull request #4

@kklimuk
Copy link
Owner

kklimuk commented May 21, 2020

hey @TvL2386 - i'll take a look at the pull request later on in the week.
(usually quite a bit busy during the workweek)
thanks for putting it together!

@georgebancila
Copy link

@kklimuk finished that workweek?

@TvL2386
Copy link
Author

TvL2386 commented Sep 26, 2023

how about now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants