Class: MPLight::Types
- Inherits:
-
Object
- Object
- MPLight::Types
- Defined in:
- lib/mplight.rb
Instance Method Summary collapse
- #additional_data ⇒ Object
- #create(id, data) ⇒ Object
- #default_to_string! ⇒ Object
- #dump(obj) ⇒ Object
-
#initialize(*args, **kwargs) ⇒ Types
constructor
A new instance of Types.
- #register(id, klass) ⇒ Object
Constructor Details
Instance Method Details
#additional_data ⇒ Object
42 43 44 |
# File 'lib/mplight.rb', line 42 def additional_data [] end |
#create(id, data) ⇒ Object
36 37 38 39 40 |
# File 'lib/mplight.rb', line 36 def create id, data c = @cls[ id] c or raise Error, "Unregistered type id: #{obj.class}" c.from_mpdata data, *additional_data end |
#default_to_string! ⇒ Object
34 |
# File 'lib/mplight.rb', line 34 def default_to_string! ; @default_to_string = true ; end |
#dump(obj) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/mplight.rb', line 25 def dump obj t = @ids[ obj.class] unless t then return if @default_to_string raise Error, "Unregistered class: #{obj.class}" end [ t, obj.to_mpdata] end |
#register(id, klass) ⇒ Object
21 22 23 |
# File 'lib/mplight.rb', line 21 def register id, klass @cls[ id], @ids[ klass] = klass, id end |