Method: ModelRecord#method_missing
- Defined in:
- lib/model/the_record.rb
#method_missing(*args) ⇒ Object
How to handle other calls
-
if attribute is specified, display it
-
if attribute= is provided, assign to the known property or create a new one
Example:
ORD.create_class :a
a = A.new
a.test= 'test' # <--- attribute: 'test=', argument: 'test'
a.test # <--- attribute: 'test' --> fetch attributes[:test]
Assignments are performed only in ruby-space.
Automatic database-updates are deactivated for now
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/model/the_record.rb', line 273 def method_missing *args # if the first entry of the parameter-array is a known attribute # proceed with the assignment if args.size == 1 attributes[args.first.to_sym] # return the attribute-value elsif args[0][-1] == "=" if args.size == 2 # if rid.rid? # update set:{ args[0][0..-2] => args.last } # else self.attributes[ args[0][0..-2] ] = args.last # end else self.attributes[ args[0][0..-2] ] = args[1 .. -1] # update set: {args[0][0..-2] => args[1 .. -1] } if rid.rid? end else raise NameError, "Unknown method call #{args.first.to_s}", caller end end |