Class: HeapInfo::Nil

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/heapinfo/nil.rb

Overview

Self define a nil like class.

Can be the return value of Process#dump and Process#dump_chunks, to prevent use the return value for calculating accidentally while exploiting remote.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *args, &block) ⇒ HeapInfo::Nil

Hook all missing methods

Examples:

# h.dump would return Nil when process not found
p h.dump(:heap)[8, 8].unpack('Q*')
#=> nil

Returns:



23
24
25
26
27
# File 'lib/heapinfo/nil.rb', line 23

def method_missing(method_sym, *args, &block) # rubocop:disable Style/MethodMissingSuper
  return nil.__send__(method_sym, *args, &block) if nil.respond_to?(method_sym)

  self
end

Instance Method Details

#respond_to_missing?Boolean

Yap

Returns:

  • (Boolean)


30
31
32
# File 'lib/heapinfo/nil.rb', line 30

def respond_to_missing?(*)
  super
end

#to_aryArray

To prevent error raised with puts Nil.instance.

Returns:

  • (Array)

    An empty array.



36
37
38
# File 'lib/heapinfo/nil.rb', line 36

def to_ary
  []
end