Skip to content

fix some logic errors #13

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

Merged
merged 2 commits into from
Jan 17, 2024

Conversation

froydnj
Copy link
Contributor

@froydnj froydnj commented Jan 16, 2024

While running bundle exec ruby benchmark.rb, I ran into an error:

st-froydnj2:message-format-rb froydnj$ RBENV_VERSION=3.1 bundle exec ruby benchmark.rb
       user     system      total        real
parse simple message  0.623193   0.003719   0.626912 (  0.626966)
format simple message/Users/froydnj/stripe/message-format-rb/lib/message_format.rb:9:in `initialize': wrong number of arguments (given 3, expected 1..2) (ArgumentError)
	from /Users/froydnj/stripe/message-format-rb/lib/message_format.rb:29:in `new'
	from /Users/froydnj/stripe/message-format-rb/lib/message_format.rb:29:in `new'
	from benchmark.rb:15:in `block (2 levels) in <main>'
	from /Users/froydnj/.rbenv/versions/3.1.4/lib/ruby/3.1.0/benchmark.rb:296:in `measure'
	from /Users/froydnj/.rbenv/versions/3.1.4/lib/ruby/3.1.0/benchmark.rb:378:in `item'
	from benchmark.rb:14:in `block in <main>'
	from /Users/froydnj/.rbenv/versions/3.1.4/lib/ruby/3.1.0/benchmark.rb:176:in `benchmark'
	from /Users/froydnj/.rbenv/versions/3.1.4/lib/ruby/3.1.0/benchmark.rb:208:in `bm'
	from benchmark.rb:6:in `<main>'

It looks like raise_on_missing_parameter wasn't passed as a keyword argument in #11. After fixing that, I ran into:

st-froydnj2:message-format-rb froydnj$ RBENV_VERSION=3.1 bundle exec ruby benchmark.rb
       user     system      total        real
parse simple message  0.625948   0.003741   0.629689 (  0.629774)
format simple message/Users/froydnj/stripe/message-format-rb/lib/message_format.rb:21:in `format': undefined method `call' for nil:NilClass (NoMethodError)

      @format.call(args)
             ^^^^^
	from benchmark.rb:17:in `block (3 levels) in <main>'
	from benchmark.rb:16:in `times'
	from benchmark.rb:16:in `block (2 levels) in <main>'
	from /Users/froydnj/.rbenv/versions/3.1.4/lib/ruby/3.1.0/benchmark.rb:296:in `measure'
	from /Users/froydnj/.rbenv/versions/3.1.4/lib/ruby/3.1.0/benchmark.rb:378:in `item'
	from benchmark.rb:14:in `block in <main>'
	from /Users/froydnj/.rbenv/versions/3.1.4/lib/ruby/3.1.0/benchmark.rb:176:in `benchmark'
	from /Users/froydnj/.rbenv/versions/3.1.4/lib/ruby/3.1.0/benchmark.rb:208:in `bm'
	from benchmark.rb:6:in `<main>'

This problem also comes from #11, which inadvertently changed the return value of Interpreter#interpret. The second commit in this PR fixes that problem, after which the benchmarks run successfully.

@mkaplan9 mkaplan9 merged commit 8604b67 into format-message:master Jan 17, 2024
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

Successfully merging this pull request may close these issues.

2 participants