lib/rom/struct.rb in rom-repository-0.2.0 vs lib/rom/struct.rb in rom-repository-0.3.0
- old
+ new
@@ -1,32 +1,37 @@
-require 'anima'
-
-require 'rom/support/class_builder'
-
module ROM
# Simple data-struct
#
# By default mappers use this as the model
#
# @api public
class Struct
- # Coerce to hash
+ # Coerces a struct to a hash
#
# @return [Hash]
#
# @api private
def to_hash
to_h
end
- # Access attribute value
+ # Reads an attribute value
#
- # @param [Symbol] name The name of the attribute
+ # @param name [Symbol] The name of the attribute
#
# @return [Object]
#
# @api public
def [](name)
- instance_variable_get("@#{name}")
+ __send__(name)
+ end
+
+ # Returns a short string representation
+ #
+ # @return [String]
+ #
+ # @api public
+ def to_s
+ "#<#{self.class}:0x#{(object_id << 1).to_s(16)}>"
end
end
end