laradji/zabbix — pull request #77 by andrewGarson (2013-05-29 16:40:59+00:00)
Title: Remove define_singleton_method in favor of opening multiple eigen classes for 1.8.7 support

This is used to create "enum" classes so that we can enforce a bit of sanity around all the magic numbers that zabbix uses in the api. I would rather not have the lwrps accepting Fixnums for things like "type" because then a person trying to use them basically has to have the api docs open instead of just having a working knowledge of zabbix.

@laradji I can "fix" this to work on 1.8, but it has a bit of strangeness to it. Basically, in order to add the methods without define_singleton_method i have to use the following trick:

eigen_class = class << self; self; end
eigen_class.send(:define_method .....)

instead of

self.send(:define_singleton_method)

The difference is that each call to the enum method (1 per value in the enumeration) will open a new eigen class and put one method into it

class Chicken
include Enumeration
enum :tuna, 0
enum :laser_beams, 1
end

self#define_singleton_method will produce [ Chicken ] < [ Chicken' ] < [ Object ] with #tuna and #laser_beams
eigen_class#define_method will produce [ Chicken ] < [ Chicken' ] < [ Chicken'' ] < [ Object ] with one method in each ' class

This should not cause any functional difference (except a slightly slower method resolution) but could cause strangeness with stacktraces or debugging.