class WebTools::Support::ObjectInfo
Attributes
info[R]
Public Class Methods
for(object)
click to toggle source
Return a new ObjectInfo
instance for the given object.
# File lib/web_tools/support/code_browser.rb, line 62 def self.for(object) new(object) end
for_id(object_id)
click to toggle source
Return a new ObjectInfo
instance for the object with the given object id.
# File lib/web_tools/support/code_browser.rb, line 57 def self.for_id(object_id) new(ObjectSpace._id2ref(object_id)) end
new(obj)
click to toggle source
# File lib/web_tools/support/code_browser.rb, line 68 def initialize(obj) @info = { } @info[:object_id] = obj.object_id @info[:class] = obj.class.name @info[:inspect] = obj.inspect @info[:instance_variables] = [] @info[:enumerated] = [] @info[:enumerated_size] = obj.respond_to?(:size) ? obj.size : nil obj.instance_variables.each do |iv| val = obj.instance_variable_get(iv) @info[:instance_variables] << [iv, val.inspect, val.object_id] end limit = 10 case obj when Enumerable, Array obj.each_with_index do |o,i| if i > limit @info[:enumerated] << '...' break else @info[:enumerated] << o.inspect end end when Hash obj.each_with_index do |pair, idx| if idx > limit @info[:enumerated] << ['', '...'] break end @info[:enumerated] << [pair[0].to_s, pair[1].inspect] end end end
Public Instance Methods
to_json(*args)
click to toggle source
# File lib/web_tools/support/code_browser.rb, line 106 def to_json(*args) @info.to_json end