Skip to content

Instantly share code, notes, and snippets.

@0x1eef
Last active July 14, 2025 10:14
Show Gist options
  • Select an option

  • Save 0x1eef/455633d8e0193b20ffe6c7cb5918a154 to your computer and use it in GitHub Desktop.

Select an option

Save 0x1eef/455633d8e0193b20ffe6c7cb5918a154 to your computer and use it in GitHub Desktop.
An implementation of Python's formatted strings in pure Ruby
require "bundler/inline"
gemfile do
gem "binding_of_caller"
end
require "binding_of_caller"
module Kernel
def f(template, vars = binding.of_caller(1))
template.gsub(/\{.+\}/) { vars.eval(_1[1..-2]) }
end
end
name = "foo"
print(f"hello {name}")
print(f"{f\"{6+7}\"}")
##
# hello foo
# 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment