Skip to content

Instantly share code, notes, and snippets.

@jaredcwhite
Last active June 23, 2021 18:14
Show Gist options
  • Save jaredcwhite/49f303aed88fba17000f6aa0db7b73c1 to your computer and use it in GitHub Desktop.
Save jaredcwhite/49f303aed88fba17000f6aa0db7b73c1 to your computer and use it in GitHub Desktop.
JS in Ruby?!
### The Setup
Kernel.define_method(:"`") do |val|
val
end
def const(val)
val
end
console = Class.new do
def log(message)
puts message
end
end.new
### Magic!
def html(&block)
block.call.gsub /\${(.*?)}/ do
block.binding.eval($1).to_s
end
end
### And Here…We…Go!
const bar = 123
const str = html{`foo ${bar + 1000} baz`}
console.log(str)
# => "foo 1123 baz"
### 😱
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment