Module: Twitter::ModelMixin::InstanceMethods
- Defined in:
- lib/vendor/twitter/lib/twitter/model.rb
Overview
Instance methods defined for Twitter::ModelMixin
module.
Instance Attribute Summary collapse
-
#client ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#bless(client) ⇒ Object
“Blesses” model object.
-
#eql?(other) ⇒ Boolean
Equality method override of Object#eql? default.
-
#to_hash ⇒ Object
Returns hash representation of model object instance.
-
#to_i ⇒ Object
Returns integer representation of model object instance.
-
#to_s ⇒ Object
Returns string representation of model object instance.
Instance Attribute Details
#client ⇒ Object
:nodoc:
49 50 51 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 49 def client @client end |
Instance Method Details
#bless(client) ⇒ Object
“Blesses” model object.
Should be overridden by model class if special behavior is expected
Expected to return blessed object (usually self
)
113 114 115 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 113 def bless(client) self.basic_bless(client) end |
#eql?(other) ⇒ Boolean
Equality method override of Object#eql? default.
Relies on the class using this mixin to provide a attributes
class method that will return an Array of attributes to check are equivalent in this #eql? override.
It is by design that the #eql? method will raise a NoMethodError if no attributes
class method exists, to alert you that you must provide it for a meaningful result from this #eql? override. Otherwise this will return a meaningless result.
60 61 62 63 64 65 66 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 60 def eql?(other) attrs = self.class.attributes attrs.each do |att| return false unless self.send(att).eql?(other.send(att)) end true end |
#to_hash ⇒ Object
Returns hash representation of model object instance.
For example,
u = Twitter::User.new(:id => 2342342, :screen_name => 'tony_blair_is_the_devil')
u.to_hash #=> {:id => 2342342, :screen_name => 'tony_blair_is_the_devil'}
This method also requires that the class method attributes
be defined to return an Array of attributes for the class.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 97 def to_hash attrs = self.class.attributes result = {} attrs.each do |att| value = self.send(att) value = value.to_hash if value.respond_to?(:to_hash) result[att] = value if value end result end |
#to_i ⇒ Object
73 74 75 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 73 def to_i @id end |
#to_s ⇒ Object
85 86 87 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 85 def to_s self.respond_to?(:text) ? @text : super.to_s end |