Class: WEEL::ReadOnlyHash

Inherits:
Object
  • Object
show all
Defined in:
lib/weel.rb

Overview

}}}

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ ReadOnlyHash

{{{



294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/weel.rb', line 294

def initialize(values)
  @__weel_values = values.transform_values do |v|
    if Object.const_defined?(:XML) && XML.const_defined?(:Smart) && v.is_a?(XML::Smart::Dom)
      v.root.to_doc
    else
      begin
        Marshal.load(Marshal.dump(v))
      rescue
        v.to_s rescue nil
      end
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/weel.rb', line 312

def method_missing(name,*args)
  if args.empty? && @__weel_values.key?(name)
    @__weel_values[name]
  elsif args.empty? && @__weel_values.key?(name.to_s)
    @__weel_values[name.to_s]
  elsif name.to_s[-1..-1] == "=" && args.length == 1
    temp = name.to_s[0..-2]
    @__weel_values[temp.to_sym] = args[0]
  elsif name.to_s == "[]=" && args.length == 2
    @__weel_values[args[0]] = args[1]
  elsif name.to_s == "[]" && args.length == 1
    @__weel_values[args[0]]
  else
    nil
  end
end

Instance Method Details

#to_json(*args) ⇒ Object



308
309
310
# File 'lib/weel.rb', line 308

def to_json(*args)
  @__weel_values.to_json(*args)
end