Skip to content

Instantly share code, notes, and snippets.

@composerinteralia
Created February 9, 2023 13:22
Show Gist options
  • Save composerinteralia/0b9681fe5afe8f6b7f40df79652b54ca to your computer and use it in GitHub Desktop.
Save composerinteralia/0b9681fe5afe8f6b7f40df79652b54ca to your computer and use it in GitHub Desktop.
Ruby symbol types
def type(obj)
case obj.object_id
when 0
:false
when 8
:nil
when 20
:true
when -> { _1[0] == 1 }
:integer
when -> { _1[1] == 1 }
:float
when -> { _1 % 20 == 8 }
id = obj.object_id / 20
case id[1..3]
when 0 then :static_sym
when 1 then :static_ivar_sym
when 3 then :static_global_sym
when 4 then :static_attrset_sym
when 5 then :static_const_sym
when 6 then :static_civar_sym
when 7 then :static_junk_sym
else
raise "WTF"
end
else
:heap
end
end
p 10.times.map { Object.new.object_id }
p 10.times.map { Object.new.object_id.object_id ^ 1 }
p type Object.new
p type :"dynamic#{"sym"}"
p type :sym
p type :@sym
p type :$sym
p type :sym=
p type :Sym
p type :@@sym
p type :"-sym"
p type 1
p type 1.0
p type true
p type false
p type nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment