Class: Backlogs::MergedArray::FlexObject

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

Instance Method Summary (collapse)

Methods inherited from Hash

#to_yaml

Constructor Details

- (FlexObject) initialize(data = {})

A new instance of FlexObject



4
5
6
7
8
9
10
11
# File 'lib/backlogs_merged_array.rb', line 4

def initialize(data = {})
  super

  data.each_pair {|k, v|
    raise "#{k} is not a symbol" unless k.is_a?(Symbol)
    self[k] = v
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method_sym, *arguments, &block)



24
25
26
27
28
29
30
31
32
# File 'lib/backlogs_merged_array.rb', line 24

def method_missing(method_sym, *arguments, &block)
  if method_sym.to_s =~ /=$/ && arguments.size == 1
    self[method_sym.to_s.gsub(/=$/, '').intern] = arguments[0]
  elsif self.include?(method_sym)
    return self[method_sym]
  else
    super(method_sym, *arguments, &block)
  end
end

Instance Method Details

- (Object) [](key)



13
14
15
16
17
# File 'lib/backlogs_merged_array.rb', line 13

def [](key)
  raise "Key '#{key}' does not exist" unless self.include?(key)
  raise "Key '#{key}' is not a symbol" unless key.is_a?(Symbol)
  return super(key)
end

- (Object) []=(key, value)



19
20
21
22
# File 'lib/backlogs_merged_array.rb', line 19

def []=(key, value)
  raise "Key '#{key}' is not a symbol" unless key.is_a?(Symbol)
  super(key, value)
end

- (Object) nilify



34
35
36
# File 'lib/backlogs_merged_array.rb', line 34

def nilify
  keys.each{|k| self[k] = nil}
end