lib/ably/modules/model_common.rb in ably-1.0.7 vs lib/ably/modules/model_common.rb in ably-1.1.0
- old
+ new
@@ -40,13 +40,26 @@
# @return [Integer] Compute a hash-code for this hash. Two hashes with the same content will have the same hash code
def hash
attributes.hash
end
+ def to_s
+ representation = attributes.map do |key, val|
+ if val.nil?
+ nil
+ else
+ val_str = val.to_s
+ val_str = "#{val_str[0...80]}..." if val_str.length > 80
+ "#{key}=#{val_str}"
+ end
+ end
+ "<#{self.class.name}: #{representation.compact.join(', ')}>"
+ end
+
module ClassMethods
# Return a new instance of this object using the provided JSON-like object or JSON string
- # @param [Hash, String] JSON-like object or JSON string
- # @return a new instance o this object
+ # @param json_like_object [Hash, String] JSON-like object or JSON string
+ # @return a new instance to this object
def from_json(json_like_object)
if json_like_object.kind_of?(String)
new(JSON.parse(json_like_object))
else
new(json_like_object)