Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created June 9, 2023 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gr33n7007h/512c5895ec9ea4cd57bc7d82095a916f to your computer and use it in GitHub Desktop.
Save gr33n7007h/512c5895ec9ea4cd57bc7d82095a916f to your computer and use it in GitHub Desktop.
read globals w/o eval
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