Class: Range

Inherits:
Object show all
Defined in:
lib/rbyaml/rubytypes.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.yaml_new(klass, tag, val) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/rbyaml/rubytypes.rb', line 202

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' => RbYAML.load( "--- #{r1}" ),
      'end' => RbYAML.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 = RbYAML::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 RbYAML::TypeError, "Invalid Range: " + val.inspect
  end
end

Instance Method Details

#to_yaml_node(repr) ⇒ Object



230
231
232
233
234
235
236
237
238
# File 'lib/rbyaml/rubytypes.rb', line 230

def to_yaml_node( repr )
  RbYAML::quick_emit_node( object_id, repr ) do |out|
    mep = {'begin' => self.begin, 'end' => self.end, 'excl' => self.exclude_end?}
    to_yaml_properties.each do |m|
      mep[m] = instance_variable_get( m )
    end
    out.map( taguri, mep, to_yaml_style )
  end
end