lib/pry/pry_class.rb in pry-0.4.8 vs lib/pry/pry_class.rb in pry-0.5.0pre2

- old
+ new

@@ -79,10 +79,23 @@ else obj.to_s end end + # A version of `Pry.view` that clips the output to `max_size` chars. + # In case of > `max_size` chars the `#<Object...> notation is used. + # @param obj The object to view. + # @param max_size The maximum number of chars before clipping occurs. + # @return [String] The string representation of `obj`. + def self.view_clip(obj, max_size=60) + if Pry.view(obj).size < max_size + Pry.view(obj) + else + "#<#{obj.class}:%#x>" % (obj.object_id << 1) + end + end + # Set all the configurable options back to their default values def self.reset_defaults @input = Readline @output = $stdout @commands = Pry::Commands @@ -101,7 +114,24 @@ # Return all active Pry sessions. # @return [Array<Pry>] Active Pry sessions. def self.sessions # last element in nesting array is the pry instance nesting.map(&:last) + end + + # Return a `Binding` object for `target` or return `target` if it is + # already a `Binding`. + # In the case where `target` is top-level then return `TOPLEVEL_BINDING` + # @param [Object] target The object to get a `Binding` object for. + # @return [Binding] The `Binding` object. + def self.binding_for(target) + if target.is_a?(Binding) + target + else + if target == TOPLEVEL_BINDING.eval('self') + TOPLEVEL_BINDING + else + target.__binding__ + end + end end end