Class: Range

Class | Range
In: | yaml/rubytypes.rb
Parent: | Object

### Methods

to_yaml yaml_new

### Public Class methods

yaml_new( klass, tag, val )

[Source]

    # File yaml/rubytypes.rb, line 200
        def Range.yaml_new( klass, tag, val )
            inr = %r'(\w+|[+-]?\d+(?:\.\d+)?(?:e[+-]\d+)?|"(?:[^\\"]|\\.)*")'
            opts = {}
            if String === val and val =~ /^#{inr}(\.{2,3})#{inr}$/o
                r1, rdots, r2 = $1, $2, $3
                opts = {
                    'begin' => YAML.load( "--- #{r1}" ),
                    'end' => YAML.load( "--- #{r2}" ),
                    'excl' => rdots.length == 3
                }
                val = {}
            elsif Hash === val
                opts['begin'] = val.delete('begin')
                opts['end'] = val.delete('end')
                opts['excl'] = val.delete('excl')
            end
            if Hash === opts
                r = YAML::object_maker( klass, {} )
                # Thank you, NaHi
                Range.instance_method(:initialize).
                      bind(r).
                      call( opts['begin'], opts['end'], opts['excl'] )
                val.each { |k,v| r.instance_variable_set( k, v ) }
                r
            else
                raise YAML::TypeError, "Invalid Range: " + val.inspect
            end
        end

### Public Instance methods

to_yaml( opts = {} )

[Source]

    # File yaml/rubytypes.rb, line 228
            def to_yaml( opts = {} )
                    YAML::quick_emit( object_id, opts ) do |out|
                # if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or
                #   self.end.is_complex_yaml? or self.end.respond_to? :to_str or
                #   not to_yaml_properties.empty?
                    out.map( taguri, to_yaml_style ) do |map|
                        map.add( 'begin', self.begin )
                        map.add( 'end', self.end )
                        map.add( 'excl', self.exclude_end? )
                        to_yaml_properties.each do |m|
                            map.add( m, instance_variable_get( m ) )
                        end
                    end
                # else
                #     out.scalar( taguri ) do |sc|
                #         sc.embed( self.begin )
                #         sc.concat( self.exclude_end? ? "..." : ".." )
                #         sc.embed( self.end )
                #     end
                # end
            end
            end

[Validate]