Class: Ohm::Types::Serialized
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(raw) ⇒ Serialized
constructor
A new instance of Serialized.
- #respond_to?(method) ⇒ Boolean
- #to_s ⇒ Object (also: #inspect)
- #type ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(raw) ⇒ Serialized
Returns a new instance of Serialized.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/ohm/contrib/typecast.rb', line 163 def initialize(raw) @object = case raw when self.class::RAW raw when ::String begin ::JSON.parse(raw) rescue ::JSON::ParserError raw end when self.class raw.object else ::Kernel.raise ::TypeError, "%s does not accept %s" % [self.class, raw.inspect] end end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
161 162 163 |
# File 'lib/ohm/contrib/typecast.rb', line 161 def object @object end |
Instance Method Details
#==(other) ⇒ Object
181 182 183 |
# File 'lib/ohm/contrib/typecast.rb', line 181 def ==(other) object == other end |
#respond_to?(method) ⇒ Boolean
190 191 192 |
# File 'lib/ohm/contrib/typecast.rb', line 190 def respond_to?(method) object.respond_to?(method) end |
#to_s ⇒ Object Also known as: inspect
185 186 187 |
# File 'lib/ohm/contrib/typecast.rb', line 185 def to_s object.to_json end |
#type ⇒ Object
194 195 196 |
# File 'lib/ohm/contrib/typecast.rb', line 194 def type self.class::RAW end |