Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the mysterious Data Class in Ruby?

Tags:

Today, I accidentally discovered the mysterious Data class in Ruby, and I can't find any useful information upon what it does, or why it's there. I assume it's part of the language implementation itself.

Does anybody know what it does?

mbp-scott:~ scott$ irb
ruby-1.9.3-p0 :001 > Data
=> Data
ruby-1.9.3-p0 :002 > Data.is_a? Module
=> true
ruby-1.9.3-p0 :003 > Data.is_a? Class
=> true
ruby-1.9.3-p0 :004 > Data.ancestors
=> [Data, Object, Kernel, BasicObject]
ruby-1.9.3-p0 :005 > Data.methods
=> [:allocate, :new, :superclass, :freeze, :===, :==, :<=>, :<, :<=, :>,
:>=, :to_s,:included_modules, :include?, :name, :ancestors, :instance_methods,
:public_instance_methods, :protected_instance_methods, :private_instance_methods,
:constants, :const_get, :const_set, :const_defined?, :const_missing, :class_variables,
:remove_class_variable, :class_variable_get, :class_variable_set,
:class_variable_defined?, :public_constant, :private_constant, :module_exec,
:class_exec, :module_eval, :class_eval, :method_defined?, :public_method_defined?,
:private_method_defined?, :protected_method_defined?, :public_class_method
:private_class_method, :autoload, :autoload?, :instance_method, :public_instance_method,
:nil?, :=~, :!~, :eql?, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup,
:initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?,
:inspect, :methods, :singleton_methods, :protected_methods, :private_methods,
:public_methods, :instance_variables, :instance_variable_get, :instance_variable_set,
:instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send,
:public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method,
:public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?,
:!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
ruby-1.9.3-p0 :006 > Data.instance_variables
=> []
ruby-1.9.3-p0 :007 > self
=> main
like image 792
Scott Avatar asked Dec 08 '11 17:12

Scott


1 Answers

A few information from C-API documentation:

It is defined on object.c. marshal.c uses it as a temporary internal container type here, here and here. stringio.c uses as the superclass of StringIO. error.c uses as the superclass of NameError::message (appears to be inaccessible from ruby side as doesn't start with a capital letter). Is superclass of Iconv in iconv.c.

It is implementation specific and should not be public. Just don't use it.

like image 90
Guilherme Bernal Avatar answered Sep 27 '22 19:09

Guilherme Bernal