Created
June 9, 2023 04:28
-
-
Save gr33n7007h/512c5895ec9ea4cd57bc7d82095a916f to your computer and use it in GitHub Desktop.
read globals w/o eval
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
require 'fiddle' | |
module Kernel | |
fname = 'rb_gv_get' | |
if Fiddle::Handle::DEFAULT.sym_defined?(fname) | |
sym = Fiddle::Handle::DEFAULT.sym(fname) | |
fun = Fiddle::Function.new(sym, [:const_string], :voidp, name: fname) | |
define_method(fname, &fun) | |
end | |
def global_variable_get(name) = rb_gv_get(name).to_value | |
end | |
$kitty_katz = "π±ππΉπ»" | |
puts global_variable_get('kitty_katz').grapheme_clusters.sample #=> π» | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment