# module Kernel

shell command:

Additional alternations to Kernel/Object class: Data element class support, quota support functions

### Public Instance Methods

content_size_used(counted=[], options={}) click to toggle source

    # File lib/gxg.rb, line 243
    def content_size_used(counted=[], options={})
      # returns how many bytes are consumed by this *instance* (and elements) and its instance variables (and elements) all the way down.
      unless counted.is_a?(Array)
        if counted.is_a?(Hash)
          options = counted
        end
        counted = []
      end
      exclusions = [nil]
      if options[:exclude]
        unless options[:exclude].is_a?(Array)
          options[:exclude] = [(options[:exclude])]
        end
        exclusions = (options[:exclude] << nil)
      end
      count = 0
      unless (counted.include?(self) || exclusions.include?(self))
        counted << self
        if self.is_any?(::Array,::Hash,::Struct)
          self.search do |entry,selector,container|
            unless counted.include?(entry)
              unless selector.is_a?(Numeric)
                count += selector.content_size_used(counted, {:exclude => exclusions})
              end
              count += entry.content_size_used(counted, {:exclude => exclusions})
            end
          end
        else
          unless self.is_a?(::GxG::ByteArray)
            if self.respond_to?(:bytesize)
              count = self.bytesize
            else
              if self.respond_to?(:size)
                count = self.size
              else
                # TODO: cull the size of more exotic classes by class:
                count = 0
              end
            end
          end
        end
      end
      #
      self.instance_variables.to_enum.each do |ivar|
        # must decode from symbol to actual instance var
        ivar = self.instance_eval(ivar.to_s)
        unless (counted.include?(ivar) || exclusions.include?(ivar))
          if ivar.is_any?(::Array,::Hash,::Struct)
            ivar.search do |entry,selector,container|
              unless (counted.include?(entry) || exclusions.include?(entry))
                unless selector.is_a?(Numeric)
                  # Symbols and Strings in Hashes take up heap space, so lets count it.
                  count += selector.content_size_used(counted, {:exclude => exclusions})
                end
                count += entry.content_size_used(counted, {:exclude => exclusions})
              end
            end
          else
            unless (counted.include?(ivar) || exclusions.include?(ivar))
              count += ivar.content_size_used(counted, {:exclude => exclusions}).to_i
              # Subsequent references to this object will only incur an RVALUE slot count (me thinks)
              counted << ivar
            end
          end
        end
      end
      count
    end

shell(command=nil,&block) click to toggle source

    # File lib/gxg.rb, line 3
    def shell(command=nil,&block)
      if command.to_s.size > 0
        block.call(`#{command.to_s}`)
        true
      end
    end

slots_used(counted=[], options={}) click to toggle source

alias :stock_enum_for :enum_for alias :stock_to_enum :to_enum def enum_for(method=:each,*args)

    GxG::Enumerator.new(self,method,*args)

end alias :to_enum :enum_for

    # File lib/gxg.rb, line 191
    def slots_used(counted=[], options={})
      # returns how many heap slots are consumed by this *instance* (and elements) and its instance variables (and elements) all the way down.
      # General Research: see memprof for how much is consumed by a Module or Class or Method.
      # TODO: ::Kernel#slots_used : find the byte-size of a given :method and add it to slot_count initial value.
      unless counted.is_a?(Array)
        if counted.is_a?(Hash)
          options = counted
        end
        counted = []
      end
      # warning: assumes references to nil incur no RVALUE allocation.
      exclusions = [nil]
      if options[:exclude]
        unless options[:exclude].is_a?(Array)
          options[:exclude] = [(options[:exclude])]
        end
        exclusions = (options[:exclude] << nil)
      end
      slot_count = 0
      unless (counted.include?(self) || exclusions.include?(self))
        counted << self
        slot_count = 1
        if self.is_any?(::Array,::Hash,::Set,::Struct)
          self.search do |entry,selector,container|
            unless (counted.include?(entry) || exclusions.include?(entry))
              unless selector.is_a?(Numeric)
                slot_count += selector.slots_used(counted, {:exclude => exclusions})
              end
              slot_count += entry.slots_used(counted, {:exclude => exclusions})
            end
          end
        end
      end
      self.instance_variables.to_enum.each do |ivar|
        unless (counted.include?(ivar) || exclusions.include?(ivar))
          if ivar.is_any?(::Array,::Hash,::Set,::Struct)
            ivar.search do |entry,selector,container|
              unless (counted.include?(entry) || exclusions.include?(entry))
                unless selector.is_a?(Numeric)
                  slot_count += selector.slots_used(counted, {:exclude => exclusions})
                end
                slot_count += entry.slots_used(counted, {:exclude => exclusions})
              end
            end
          else
            slot_count += ivar.slots_used(counted, {:exclude => exclusions})
          end
        end
      end
      slot_count
    end