Sha256: 3c7cb692d5371f483307b5c0b3fd5c243f12e7f3c2dda948b9c085b85923f75c
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 KB
Contents
class Boolean < TrueClass; end class Symbol [:lt, :lte, :gt, :gte, :ne, :in, :nin, :mod, :all, :size, :exists].each do |operator| define_method(operator) { MongoModel::MongoOperator.new(self, operator) } end define_method(:asc) { MongoModel::MongoOrder::Clause.new(self, :ascending) } define_method(:desc) { MongoModel::MongoOrder::Clause.new(self, :descending) } end class Object begin ObjectSpace.each_object(Class.new) {} # Exclude this class unless it's a subclass of our supers and is defined. # We check defined? in case we find a removed class that has yet to be # garbage collected. This also fails for anonymous classes -- please # submit a patch if you have a workaround. def subclasses_of(*superclasses) #:nodoc: subclasses = [] superclasses.each do |sup| ObjectSpace.each_object(class << sup; self; end) do |k| if k != sup && (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id")) subclasses << k end end end subclasses end rescue RuntimeError # JRuby and any implementations which cannot handle the objectspace traversal # above fall back to this implementation def subclasses_of(*superclasses) #:nodoc: subclasses = [] superclasses.each do |sup| ObjectSpace.each_object(Class) do |k| if superclasses.any? { |superclass| k < superclass } && (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id")) subclasses << k end end subclasses.uniq! end subclasses end end end class Class # Returns an array with the names of the subclasses of +self+ as strings. # # Integer.subclasses # => ["Bignum", "Fixnum"] def subclasses Object.subclasses_of(self).map { |o| o.to_s } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongomodel-0.1.1 | lib/mongomodel/support/core_extensions.rb |