Skip to content

Commit

Permalink
Avoid using Binding#receiver
Browse files Browse the repository at this point in the history
This feature is only available on Ruby 2.2+ and breaks older rubies.

See <https://docs.ruby-lang.org/en/2.2.0/NEWS.html> for more details.
  • Loading branch information
ivoanjo authored and nobu committed Feb 9, 2021
1 parent 0784ef0 commit 1773502
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ruby2_keywords.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def ruby2_keywords(name, *)
end
end

main = TOPLEVEL_BINDING.receiver
main = TOPLEVEL_BINDING.eval('self')
unless main.respond_to?(:ruby2_keywords, true)
# call-seq:
# ruby2_keywords(method_name, ...)
Expand Down
2 changes: 1 addition & 1 deletion test/test_keyword.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_module_ruby2_keywords
end

def test_toplevel_ruby2_keywords
main = TOPLEVEL_BINDING.receiver
main = TOPLEVEL_BINDING.eval('self')
assert_send([main, :respond_to?, :ruby2_keywords, true])
assert_operator(main.method(:ruby2_keywords).arity, :<, 0)
end
Expand Down

0 comments on commit 1773502

Please sign in to comment.