Class: RedditKit::Base
- Inherits:
-
Object
- Object
- RedditKit::Base
- Defined in:
- lib/redditkit/base.rb
Overview
A base class for RedditKitâs model objects, automatically generating attribute and predicate methods.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #[](method) ⇒ Object
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
35 36 37 38 39 40 41 |
# File 'lib/redditkit/base.rb', line 35 def initialize(attributes = {}) kind = attributes[:kind] data = attributes[:data] @attributes = data || {} @attributes[:kind] = kind end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/redditkit/base.rb', line 6 def attributes @attributes end |
Class Method Details
.attr_reader(*attrs) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/redditkit/base.rb', line 10 def attr_reader(*attrs) attrs.each do |attr| define_attribute_method(attr) define_predicate_method(attr) end end |
Instance Method Details
#[](method) ⇒ Object
43 44 45 46 47 |
# File 'lib/redditkit/base.rb', line 43 def [](method) send(method.to_sym) rescue NoMethodError nil end |