Module: CSquare::Hashable::SingletonMethods

Defined in:
lib/csquare.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_hashable(array_name) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/csquare.rb', line 240

def acts_as_hashable(array_name)
  unless self.is_a?(ClassMethods)
    #include InstanceMethods
    # extend ClassMethods

    # Add a to_h function which returns a hash of variables and their types.
    module_eval "      def to_h(as=nil)\n        h = {}\n        self.\#{array_name}.each do |obj|\n          if as == :string\n            h[obj.name] = obj.type.CustomType? || obj.type.Struct? ? obj.type.name : obj.type.to_s\n          else\n            h[obj.name] = obj.type\n          end\n        end\n        h\n      end\n    end_eval\n\n  end\nend\n", __FILE__, __LINE__