String (Class)

In: yaml/rubytypes.rb
Parent: Object

Public Instance methods

[Source]

# File yaml/rubytypes.rb, line 289
    def is_binary_data?
        ( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 )
    end

[Source]

# File yaml/rubytypes.rb, line 286
    def is_complex_yaml?
        to_yaml_fold or not to_yaml_properties.empty? or self =~ /\n.+/
    end

[Source]

# File yaml/rubytypes.rb, line 298
        def to_yaml( opts = {} )
        complex = false
        if self.is_complex_yaml?
            complex = true
        elsif opts[:BestWidth].to_i > 0
            if self.length > opts[:BestWidth] and opts[:UseFold]
                complex = true
            end
        end
                YAML::quick_emit( complex ? self.object_id : nil, opts ) { |out|
            if complex
                if not to_yaml_properties.empty?
                    out.map( self.to_yaml_type ) { |map|
                        map.add( 'str', "#{self}" )
                        to_yaml_properties.each { |m|
                            map.add( m, instance_variable_get( m ) )
                        }
                    }
                elsif self.is_binary_data?
                    out.binary_base64( self )
                elsif self =~ /^ |#{YAML::ESCAPE_CHAR}| $/
                    complex = false
                else
                    out.node_text( self, to_yaml_fold )
                end
            end
            if not complex
                ostr =  if out.options(:KeepValue)
                            self
                        elsif empty?
                            "''"
                        elsif self =~ /^[^#{YAML::WORD_CHAR}]| \#|#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}]( |$)| $|\n|\'/
                            "\"#{YAML.escape( self )}\"" 
                        elsif YAML.detect_implicit( self ) != 'str'
                            "\"#{YAML.escape( self )}\"" 
                        else
                            self
                        end
                out.simple( ostr )
            end
                }
        end

[Source]

# File yaml/rubytypes.rb, line 295
    def to_yaml_fold
        nil
    end

[Source]

# File yaml/rubytypes.rb, line 292
    def to_yaml_type
        "!ruby/string#{ if self.class != ::String; ":#{ self.class }"; end }"
    end

[Validate]