Changeset 227
- Timestamp:
- 06/11/05 19:34:39 (3 years ago)
- Location:
- trunk/lib/fm
- Files:
-
- 2 modified
-
gameobject.rb (modified) (2 diffs)
-
mixins.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/fm/gameobject.rb
r226 r227 156 156 157 157 # This must come after the declaration of the contributors method above. 158 contributors :ged 158 contributors :ged, :stillflame 159 159 160 160 ### Initialize a new FaerieMUD::GameObject. Arguments in the … … 339 339 end 340 340 341 342 #######343 private344 #######345 346 #################################################################347 ### U T I L I T Y F U N C T I O N S348 #################################################################349 350 ### Check to be sure the specified +args+ object is a Hash and contains351 ### the given +keys+. Each key in +keys+ can be either a Symbol, a352 ### String, or an Array of either.353 def checkForHashArgs( args, *keys )354 unless args.is_a?( Hash )355 raise TypeError,356 "Arguments are not in Hash form.",357 caller(1).find_all {|frame| /#{__FILE__}/ !~ frame}358 end359 360 unless keys.empty?361 nicetrace = caller( 1 ).delete_if {|frame|362 /#{__FILE__}:\d+:in/i =~ frame363 }364 keys.each {|required|365 case required366 when Symbol367 raise ArgumentError,368 "Missing required argument :#{required}",369 nicetrace unless370 args.key?( required )371 when String372 raise ArgumentError,373 "Missing required argument :#{required}",374 nicetrace unless375 args.key?( required.intern )376 when Array377 raise ArgumentError,378 "Missing required argument :#{requiredKey}",379 nicetrace unless380 required.381 collect {|ak| ak.to_s.intern }.382 find {|ak| args.keys.include?(ak) }383 end384 385 }386 end387 388 return true389 end390 391 392 341 end # class FaerieMUD::GameObject 393 342 -
trunk/lib/fm/mixins.rb
r205 r227 5 5 # Currently contains the following modules: 6 6 # 7 # [<tt>FaerieMUD::ArgCheckFunctions</tt>] 8 # Functions for checking arguments for types, signatures, and hash members. 9 # 7 10 # [<tt>FaerieMUD::Propertied</tt>] 8 11 # Adds the ability to interact with FaerieMUD::Property objects to including … … 53 56 54 57 require 'fm/exceptions' 55 56 58 57 59 module FaerieMUD … … 181 183 end 182 184 185 186 ### Check to be sure the specified +args+ object is a Hash and contains 187 ### the given +keys+. Each key in +keys+ can be either a Symbol, a 188 ### String, or an Array of either. 189 def checkForHashArgs( args, *keys ) 190 unless args.is_a?( Hash ) 191 raise TypeError, 192 "Arguments are not in Hash form.", 193 caller(1).find_all {|frame| /#{__FILE__}/ !~ frame} 194 end 195 196 unless keys.empty? 197 nicetrace = caller( 1 ).delete_if {|frame| 198 /#{__FILE__}:\d+:in/i =~ frame 199 } 200 keys.each {|required| 201 case required 202 when Symbol 203 raise ArgumentError, 204 "Missing required argument :#{required}", 205 nicetrace unless 206 args.key?( required ) 207 when String 208 raise ArgumentError, 209 "Missing required argument :#{required}", 210 nicetrace unless 211 args.key?( required.intern ) 212 when Array 213 raise ArgumentError, 214 "Missing required argument :#{requiredKey}", 215 nicetrace unless 216 required. 217 collect {|ak| ak.to_s.intern }. 218 find {|ak| args.keys.include?(ak) } 219 end 220 221 } 222 end 223 224 return true 225 end 226 183 227 end # module ArgCheckFunctions 184 228
