Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active July 31, 2021 15:03
Show Gist options
  • Save JoshCheek/43b15b9123e337ee6a118cb6ff4c7e7a to your computer and use it in GitHub Desktop.
Save JoshCheek/43b15b9123e337ee6a118cb6ff4c7e7a to your computer and use it in GitHub Desktop.
The flag that `ruby2_keywords` uses
# https://twitter.com/josh_cheek/status/1421462056994283521
require 'fiddle'
public def address() = Fiddle.dlwrap(self)
public def pointer() = Fiddle::Pointer.new(address)
public def toggle_keywords!() = (pointer[1] ^= 0b100000)
def m(a:) = a
h = {a: 1}
m *[h] rescue $! # => #<ArgumentError: wrong number of arguments (given 1, expected 0; required keyword: a)>
h.toggle_keywords!
m *[h] rescue $! # => 1
h.toggle_keywords!
m *[h] rescue $! # => #<ArgumentError: wrong number of arguments (given 1, expected 0; required keyword: a)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment