Class: Upl::Atom
Instance Attribute Summary collapse
-
#atom_t ⇒ Object
readonly
Returns the value of attribute atom_t.
Class Method Summary collapse
-
.of_term(term_t) ⇒ Object
drop the term immediately, and just keep the atom value.
-
.t_of_ruby(obj) ⇒ Object
NOTE this returns an atom_t for obj.object_id embedded in an atom.
Instance Method Summary collapse
- #==(rhs) ⇒ Object
-
#initialize(atom_t) ⇒ Atom
constructor
NOTE these are atom_t, NOT term_t and NOT Fiddle::Pointer to atom_t.
- #inspect ⇒ Object
- #pretty_print(pp) ⇒ Object
-
#to_obj_id ⇒ Object
return the object_id embedded in the atom, or nil if it’s not an embedded object_id.
-
#to_ruby ⇒ Object
return the ruby object associated with the object_id embedded in the atom.
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(atom_t) ⇒ Atom
NOTE these are atom_t, NOT term_t and NOT Fiddle::Pointer to atom_t
4 5 6 7 8 9 |
# File 'lib/upl/atom.rb', line 4 def initialize( atom_t ) @atom_t = atom_t # pretty much all other methods need chars, so just do it now. @chars = (::Upl::Extern::PL_atom_chars @atom_t).to_s.freeze end |
Instance Attribute Details
#atom_t ⇒ Object (readonly)
Returns the value of attribute atom_t.
18 19 20 |
# File 'lib/upl/atom.rb', line 18 def atom_t @atom_t end |
Class Method Details
Instance Method Details
#==(rhs) ⇒ Object
55 56 57 |
# File 'lib/upl/atom.rb', line 55 def == rhs atom_t == rhs.atom_t end |
#inspect ⇒ Object
67 |
# File 'lib/upl/atom.rb', line 67 def inspect; to_sym end |
#pretty_print(pp) ⇒ Object
69 70 71 72 73 |
# File 'lib/upl/atom.rb', line 69 def pretty_print pp pp.text atom_t pp.text '-' pp.text to_s end |
#to_obj_id ⇒ Object
return the object_id embedded in the atom, or nil if it’s not an embedded object_id
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/upl/atom.rb', line 27 def to_obj_id if instance_variable_defined? :@to_obj_id @to_obj_id else @to_obj_id = if @chars =~ /^ruby-(\d+)/ $1.to_i end end end |
#to_ruby ⇒ Object
return the ruby object associated with the object_id embedded in the atom
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/upl/atom.rb', line 39 def to_ruby if to_obj_id ObjectSpace._id2ref to_obj_id else case _sym = to_sym when :false; false when :true; true else _sym end end rescue RangeError # object with the given obj_id no longer exists in ruby, so just return # the symbol with the embedded object_id. to_sym end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/upl/atom.rb', line 63 def to_s @chars end |
#to_sym ⇒ Object
59 60 61 |
# File 'lib/upl/atom.rb', line 59 def to_sym @chars.to_sym end |