Created
September 13, 2019 07:28
-
-
Save amolpujari/ad1f4b61a3ffc50ab4e90dfe9b0dbac1 to your computer and use it in GitHub Desktop.
inspect ruby object in private
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.class_eval do | |
def private_inspect | |
memo = {} | |
self.instance_variables.inject(memo) do |memo, var| | |
memo[var] = self.instance_variable_get(var).to_s | |
memo | |
end | |
except = [:__, :_, :_ex_, :_pry_, :_out_, :_in_, :_dir_, :_file_] | |
(self.__binding__.local_variables - except).inject(memo) do |memo, var| | |
memo[var] = self.__binding__.local_variable_get(var).to_s | |
memo | |
end | |
memo | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment