Class: DevRuby::Objects::BaseObject
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- DevRuby::Objects::BaseObject
- Defined in:
- lib/dev_ruby/objects/base_object.rb
Direct Known Subclasses
Article, Comment, Error, Follower, Listing, Organization, PodcastEpisode, ProfileImage, Tag, User, VideoArticle
Instance Method Summary collapse
-
#initialize(attributes) ⇒ BaseObject
constructor
A new instance of BaseObject.
- #to_ostruct(obj) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ BaseObject
Returns a new instance of BaseObject.
8 9 10 |
# File 'lib/dev_ruby/objects/base_object.rb', line 8 def initialize(attributes) super to_ostruct(attributes) end |
Instance Method Details
#to_ostruct(obj) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dev_ruby/objects/base_object.rb', line 12 def to_ostruct(obj) case obj when Hash OpenStruct.new(obj.transform_values { |val| to_ostruct(val) }) when Array obj.map { |o| to_ostruct(o) } else # Assumed to be a primitive value obj end end |