module Must::StructInfo::Browser
Public Instance Methods
compact(obj)
click to toggle source
# File lib/must/struct_info.rb, line 17 def compact(obj) case obj when Hash obj.empty? ? Hash : Hash[*obj.first.map{|i| compact(i)}] when Array obj.empty? ? Array : [compact(obj.first)] else classify(obj) end end
same?(src, dst)
click to toggle source
# File lib/must/struct_info.rb, line 39 def same?(src, dst) case src when Hash return true if dst == Hash dst.must(Hash) return true if src.empty? return true if dst.empty? key1, val1 = src.first key2, val2 = dst.first key1.must(key2) val1.must(val2) when Array return true if dst == Array dst.must(Array) return true if src.empty? return true if dst.empty? src.first.must(dst.first) else # 1.must.struct(2) # 1.must.struct(Integer) dst_class = classify(dst) return true if classify(src).ancestors.include?(dst_class) # Fixnum.must.struct(2) return true if class?(src) and src.ancestors.include?(dst_class) return false end return true rescue Must::Invalid return false end
types(obj)
click to toggle source
# File lib/must/struct_info.rb, line 28 def types(obj) case obj when Hash ([Hash] + (obj.first || []).map{|i| types(i)}.flatten).uniq when Array ([Array] + obj.map{|i| types(i)}.flatten).uniq else [classify(obj)] end end