Skip to content

Instantly share code, notes, and snippets.

@oleganza
Created February 2, 2009 10:04
Show Gist options
  • Save oleganza/56862 to your computer and use it in GitHub Desktop.
Save oleganza/56862 to your computer and use it in GitHub Desktop.
class ::Object
def hide_inspect_for_one_shot(replacement = "#<#{self.class}:0x#{object_id.to_s(16)}>")
return unless self
mc = class <<self; self; end
mc.send(:alias_method, :inspect_457290, :inspect)
mc.send(:define_method, :inspect) do
mc.send(:alias_method, :inspect, :inspect_457290)
replacement
end
end
end
#
# Example (console.rb):
#
def mql(json)
r = client.mqlread(json)
pp r
r.hide_inspect_for_one_shot("≈#{r.to_s.size} bytes")
r # this will show "≈123 bytes" instead of a verbose data dump.
end
__END__
>> mql(:id => "/en/lasagna", :type => [])
{"type"=>
["/common/topic",
"/user/skud/food/noodle",
"/food/ingredient",
"/user/skud/food/topic",
"/food/dish"],
"id"=>"/en/lasagna"}
=> ≈99 bytes
>> _
=> {"type"=>["/common/topic", "/user/skud/food/noodle", "/food/ingredient", "/user/skud/food/topic", "/food/dish"], "id"=>"/en/lasagna"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment