Sha256: e4d4a601c8c0fff4aec9f01ff307b6c98ec485736ea81db8ed930cf5e0eb3fdc

Contents?: true

Size: 968 Bytes

Versions: 21

Compression:

Stored size: 968 Bytes

Contents

##
# Object extension to allow numbered LP variables to be initialised dynamically using the following
# syntax.
#
# [Capitalized_varname][lp var type suffix]
#
# Where lp var type suffix is either _b for binary, _i for integer, or _f for float.
# I.e
#
# Rating_i is the equivalent of Rating (type integer)
# Is_happy_b is the equivalent of Is_happy (type binary/boolean)
##
class << Object
  alias_method :old_const_missing, :const_missing
  def const_missing(value)
    method_name = "#{value}".split("::")[-1] rescue ""
    if (("A".."Z").include?(method_name[0]))
      if(method_name.end_with?("b"))
        return BV.send(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
      elsif(method_name.end_with?("i"))
        return IV.send(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
      elsif(method_name.end_with?("f"))
        return LV.send(method_name[0..(method_name[-2] == "_" ? -3 : -2)])
      end
    end
    old_const_missing(value)
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rulp-0.0.29 lib/extensions/object_extensions.rb
rulp-0.0.27 lib/extensions/object_extensions.rb
rulp-0.0.26 lib/extensions/object_extensions.rb
rulp-0.0.25 lib/extensions/object_extensions.rb
rulp-0.0.24 lib/extensions/object_extensions.rb
rulp-0.0.23 lib/extensions/object_extensions.rb
rulp-0.0.22 lib/extensions/object_extensions.rb
rulp-0.0.21 lib/extensions/object_extensions.rb
rulp-0.0.20 lib/extensions/object_extensions.rb
rulp-0.0.19 lib/extensions/object_extensions.rb
rulp-0.0.18 lib/extensions/object_extensions.rb
rulp-0.0.17 lib/extensions/object_extensions.rb
rulp-0.0.16 lib/extensions/object_extensions.rb
rulp-0.0.15 lib/extensions/object_extensions.rb
rulp-0.0.14 lib/extensions/object_extensions.rb
rulp-0.0.13 lib/extensions/object_extensions.rb
rulp-0.0.12 lib/extensions/object_extensions.rb
rulp-0.0.11 lib/extensions/object_extensions.rb
rulp-0.0.10 lib/extensions/object_extensions.rb
rulp-0.0.9 lib/extensions/object_extensions.rb