Top Level Namespace
Defined Under Namespace
Modules: AbstractClass, RLTK Classes: Class, FalseClass, Integer, Object, TrueClass
Instance Method Summary collapse
-
#check_array_type(array, type, blame = nil, strict = false) ⇒ Object
A helper method for type checking Ruby array values.
-
#check_cg_array_type(array, type = RLTK::CG::Type, blame = 'el_types', strict = false) ⇒ Array<Type>
This helper function checks to make sure that an array of objects are all sub-classses of Type or instances of a sub-class of Type.
-
#check_cg_type(o, type = RLTK::CG::Type, blame = 'type', strict = false) ⇒ Type
This helper function checks to make sure that an object is a sub-class of Type or an instance of a sub-class of Type.
-
#check_type(o, type, blame = nil, strict = false) ⇒ Object
A helper method for type checking Ruby values.
-
#make_ptr_to_elements(size_or_values, &block) ⇒ FFI::MemoryPointer
A helper function for creating constant array, vector, and struct types.
Instance Method Details
#check_array_type(array, type, blame = nil, strict = false) ⇒ Object
A helper method for type checking Ruby array values.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rltk/util/monkeys.rb', line 48 def check_array_type(array, type, blame = nil, strict = false) array.each do |o| type_ok = if strict then o.instance_of?(type) else o.is_a?(type) end if not type_ok if blame raise ArgumentError, "Parameter #{blame} must contain instances of the #{type.name} class." else raise ArgumentError, "Expected an object of type #{type.name}." end end end end |
#check_cg_array_type(array, type = RLTK::CG::Type, blame = 'el_types', strict = false) ⇒ Array<Type>
This helper function checks to make sure that an array of objects are all sub-classses of Type or instances of a sub-class of Type. If a class is present in the array parameter it is expected to be a singleton class and will be instantiated via the instance method.
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/rltk/cg/type.rb', line 485 def check_cg_array_type(array, type = RLTK::CG::Type, blame = 'el_types', strict = false) array.map do |o| if o.is_a?(Class) type_ok = if strict then o == type else o.subclass_of?(type) end if type_ok if o.includes_module?(Singleton) o.instance else raise ArgumentError, "The #{o.name} class (passed in parameter #{blame}) must be instantiated directly." end else raise ArgumentError, "The #{o.name} class (passed in parameter #{blame}) does not inherit from the #{type.name} class." end else type_ok = if strict then o.instance_of(type) else o.is_a?(type) end if type_ok o else raise ArgumentError, "Parameter #{blame} must contain instances of the #{type.name} class." end end end end |
#check_cg_type(o, type = RLTK::CG::Type, blame = 'type', strict = false) ⇒ Type
This helper function checks to make sure that an object is a sub-class of Type or an instance of a sub-class of Type. If a class is passed in the o parameter it is expected to be a singleton class and will be instantiated via the instance method.
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/rltk/cg/type.rb', line 451 def check_cg_type(o, type = RLTK::CG::Type, blame = 'type', strict = false) if o.is_a?(Class) type_ok = if strict then o == type else o.subclass_of?(type) end if type_ok if o.includes_module?(Singleton) o.instance else raise ArgumentError, "The #{o.name} class (passed as parameter #{blame}) must be instantiated directly." end else raise ArgumentError, "The #{o.name} class (passed as parameter #{blame} does not inherit from the #{type.name} class." end else check_type(o, type, blame, strict) end end |
#check_type(o, type, blame = nil, strict = false) ⇒ Object
A helper method for type checking Ruby values.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rltk/util/monkeys.rb', line 24 def check_type(o, type, blame = nil, strict = false) type_ok = if strict then o.instance_of?(type) else o.is_a?(type) end if type_ok o else if blame raise ArgumentError, "Parameter #{blame} must be an instance of the #{type.name} class. Received an instance of #{o.class.name}." else raise ArgumentError, "Expected an object of type #{type.name}. Received an instance of #{o.class.name}." end end end |
#make_ptr_to_elements(size_or_values, &block) ⇒ FFI::MemoryPointer
A helper function for creating constant array, vector, and struct types. This method should never be used by library users.
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 |
# File 'lib/rltk/cg/value.rb', line 1217 def make_ptr_to_elements(size_or_values, &block) values = case size_or_values when Integer raise ArgumentError, 'Block not given.' if not block_given? ::Array.new(size_or_values, &block) else size_or_values end returning(FFI::MemoryPointer.new(:pointer, values.size)) do |ptr| ptr.write_array_of_pointer(values) end end |