Class: RecordX
- Inherits:
-
Object
show all
- Defined in:
- lib/recordx.rb
Overview
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
57
58
59
60
61
62
|
# File 'lib/recordx.rb', line 57
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
#id ⇒ Object
Returns the value of attribute id.
7
8
9
|
# File 'lib/recordx.rb', line 7
def id
@id
end
|
Instance Method Details
#[](k) ⇒ Object
30
|
# File 'lib/recordx.rb', line 30
def [](k) @h[k] end
|
#[]=(k, v) ⇒ Object
31
|
# File 'lib/recordx.rb', line 31
def []=(k,v) @h[k] = v end
|
#delete ⇒ Object
37
38
39
|
# File 'lib/recordx.rb', line 37
def delete()
@callerx.delete @id
end
|
#each(&blk) ⇒ Object
Also known as:
each_pair
34
|
# File 'lib/recordx.rb', line 34
def each(&blk) @h.each(&blk) end
|
#h ⇒ Object
Also known as:
to_h
41
42
43
|
# File 'lib/recordx.rb', line 41
def h()
@h
end
|
#inspect ⇒ Object
45
46
47
|
# File 'lib/recordx.rb', line 45
def inspect()
"<object #%s>" % [self.object_id]
end
|
#keys ⇒ Object
32
|
# File 'lib/recordx.rb', line 32
def keys() @h.keys end
|
#update(h) ⇒ Object
51
52
53
|
# File 'lib/recordx.rb', line 51
def update(h)
h.each {|name,value| self.method((name.to_s + '=').to_sym).call(value) }
end
|
#values ⇒ Object
33
|
# File 'lib/recordx.rb', line 33
def values() @h.keys end
|