Class: Hermeneutics::URLText::Dict

Inherits:
Hash
  • Object
show all
Defined in:
lib/hermeneutics/escape.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Dict

Returns a new instance of Dict.

Yields:

  • (_self)

Yield Parameters:



329
330
331
332
# File 'lib/hermeneutics/escape.rb', line 329

def initialize
  super
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/hermeneutics/escape.rb', line 350

def method_missing sym, *args
  if args.empty? and not sym =~ /[!?=]\z/ then
    self[ sym]
  else
    first, *rest = args
    if rest.empty? and sym =~ /=\z/ then
      self[ sym] = first
    else
      super
    end
  end
end

Class Method Details

.create {|i| ... } ⇒ Object

Yields:

  • (i)


323
324
325
326
327
# File 'lib/hermeneutics/escape.rb', line 323

def create
  i = new
  yield i
  i
end

Instance Method Details

#[](key) ⇒ Object



333
334
335
# File 'lib/hermeneutics/escape.rb', line 333

def [] key
  super key.to_sym
end

#[]=(key, val) ⇒ Object



336
337
338
# File 'lib/hermeneutics/escape.rb', line 336

def []= key, val
  super key.to_sym, val
end

#parse(key, val) ⇒ Object



343
344
345
346
347
348
349
# File 'lib/hermeneutics/escape.rb', line 343

def parse key, val
  self[ key] = case val
    when nil                             then nil
    when /\A(?:[+-]?[1-9][0-9]{,9}|0)\z/ then val.to_i
    else                                      val.to_s.notempty?
  end
end

#update(hash) ⇒ Object Also known as: merge!



339
340
341
# File 'lib/hermeneutics/escape.rb', line 339

def update hash
  hash.each { |k,v| self[ k] = v }
end