Class: HeapInfo::Nil

Inherits:
Object
  • Object
show all
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:


17
18
19
20
# File 'lib/heapinfo/nil.rb', line 17

def method_missing(method_sym, *args, &block)
  return nil.__send__(method_sym, *args, &block) if nil.respond_to?(method_sym)
  self || super
end

Instance Method Details

#respond_to_missing?Boolean

Yap

Returns:

  • (Boolean)

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

def respond_to_missing?(*)
  super
end

#to_aryArray

To prevent error raised when using puts Nil.new.

Returns:

  • (Array)

    Empty array


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

def to_ary
  []
end