Module: Kernel
- Defined in:
- lib/extensions/kernel_extensions.rb,
lib/extensions/kernel_extensions.rb
Overview
Kernel extension to allow numbered LP variables to be initialised dynamically using the following syntax.
[Capitalized_varname][lp var type suffix]( integer )
This is similar to the syntax defined in the object extensions but allows for numbered suffixes to quickly generate ranges of similar variables.
Where lp var type suffix is either _b for binary, _i for integer, or _f for float. I.e
Rating_i(5) is the equivalent of Rating_5 (type integer) Is_happy_b(2) is the equivalent of Is_happy_2 (type binary/boolean) …
Defined Under Namespace
Classes: AssertionException
Instance Method Summary collapse
- #_profile ⇒ Object
-
#assert(truthy = false) ⇒ Object
If assertion returns false we return a new assertion exception with the failing file and line, and attempt to return the failed source if accessible.
- #method_missing(value, *args) ⇒ Object
- #old_method_missing ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(value, *args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/extensions/kernel_extensions.rb', line 19 def method_missing(value, *args) method_name = "#{value}" rescue "" if ("A".."Z").cover?(method_name[0]) if method_name.end_with?(BV.suffix) method_name = method_name.chomp(BV.suffix).chomp("_") return BV.definition(method_name, args) elsif method_name.end_with?(IV.suffix) method_name = method_name.chomp(IV.suffix).chomp("_") return IV.definition(method_name, args) elsif method_name.end_with?(LV.suffix) method_name = method_name.chomp(LV.suffix).chomp("_") return LV.definition(method_name, args) end end old_method_missing(value, *args) end |
Instance Method Details
#_profile ⇒ Object
36 37 38 39 40 |
# File 'lib/extensions/kernel_extensions.rb', line 36 def _profile start = Time.now return_value = yield return return_value, Time.now - start end |
#assert(truthy = false) ⇒ Object
If assertion returns false we return a new assertion exception with the failing file and line, and attempt to return the failed source if accessible.
61 62 63 64 65 66 67 |
# File 'lib/extensions/kernel_extensions.rb', line 61 def assert(truthy=false) unless truthy || (block_given? && yield) file, line = caller[0].split(":") = "Assertion Failed! < #{file}:#{line}:#{ SCRIPT_LINES__[file][line.to_i - 1][0..-2] rescue ''} >" raise AssertionException.new() end end |
#old_method_missing ⇒ Object
18 |
# File 'lib/extensions/kernel_extensions.rb', line 18 alias_method :old_method_missing, :method_missing |