Last active
June 23, 2021 18:14
-
-
Save jaredcwhite/49f303aed88fba17000f6aa0db7b73c1 to your computer and use it in GitHub Desktop.
JS in Ruby?!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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