Class: Object

Inherits:
BasicObject
Defined in:
lib/zaml.rb

Overview

##############################################################

Behavior for custom classes

##############################################################

Instance Method Summary (collapse)

Instance Method Details

- (Object) to_yaml_properties



120
121
122
# File 'lib/zaml.rb', line 120

def to_yaml_properties
instance_variables.sort        # Default YAML behavior
end

- (Object) to_zaml(z)



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/zaml.rb', line 126

def to_zaml(z)
z.first_time_only(self) {
    z.emit(zamlized_class_name(Object)) 
    z.nested {
        instance_variables = to_yaml_properties
        if instance_variables.empty?
            z.emit(" {}")
          else
            instance_variables.each { |v|
                z.nl
                v[1..-1].to_zaml(z)       # Remove leading '@'
                z.emit(': ')
                instance_variable_get(v).to_zaml(z)
                }
          end
        }
    }
end

- (Object) zamlized_class_name(root)



123
124
125
# File 'lib/zaml.rb', line 123

def zamlized_class_name(root)
"!ruby/#{root.name.downcase}#{self.class == root ? '' : ":#{self.class.name}"}"
end