Class: RecordX

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

Overview

file: recordx.rb

Defined Under Namespace

Classes: RXHash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h = {}, callerx = nil, id = nil) ⇒ RecordX

Returns a new instance of RecordX.



23
24
25
26
27
28
# File 'lib/recordx.rb', line 23

def initialize(h={}, callerx=nil, id=nil )

  @callerx, @id = callerx, id    
  @h = RXHash.new(self).merge h
  h.each {|name,val| attr_accessor2(name.to_s, val) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *raw_args) ⇒ Object (private)



50
51
52
53
54
# File 'lib/recordx.rb', line 50

def method_missing(method_name, *raw_args)
  arg = raw_args.length > 0 ? raw_args.first : nil
  attr_accessor2(method_name[/\w+/], arg)
  arg ? self.send(method_name, arg) : self.send(method_name)    
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/recordx.rb', line 7

def id
  @id
end

Instance Method Details

#deleteObject



30
31
32
# File 'lib/recordx.rb', line 30

def delete()
  @callerx.delete @id
end

#hObject Also known as: to_h



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

def h()
  @h
end

#inspectObject



38
39
40
# File 'lib/recordx.rb', line 38

def inspect()
  "<object #%s>" % [self.object_id]
end

#update(h) ⇒ Object



44
45
46
# File 'lib/recordx.rb', line 44

def update(h)
  h.each {|name,value| self.method((name.to_s + '=').to_sym).call(value) }
end