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 35 36 |
# File 'lib/extensions/kernel_extensions.rb', line 19 def method_missing(value, *args) method_name = "#{value}" rescue "" start = method_name[0] if (start <= "Z" && start >= "A") case method_name[-1] when "b" method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)] return BV.definition(method_name, args) when "i" method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)] return IV.definition(method_name, args) when "f" method_name = method_name[0..(method_name[-2] == "_" ? -3 : -2)] return LV.definition(method_name, args) end end old_method_missing(value, *args) end |
Instance Method Details
#_profile ⇒ Object
38 39 40 41 42 |
# File 'lib/extensions/kernel_extensions.rb', line 38 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.
63 64 65 66 67 68 69 |
# File 'lib/extensions/kernel_extensions.rb', line 63 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 |