### Home Classes Methods

### In Files

- lib/twitter/base.rb

### Parent

Object

### Methods

- ::attr_reader
- ::define_attribute_method
- ::define_predicate_method
- ::define_uri_method
- ::deprecate_attribute_method
- ::display_uri_attr_reader
- ::new
- ::object_attr_reader
- ::predicate_attr_reader
- ::uri_attr_reader
- #[]

### Included Modules

- Memoizable
- Twitter::Utils

### Class/Module Index

Quicksearch

- Twitter
- Twitter::Arguments
- Twitter::Base
- Twitter::BasicUser
- Twitter::Client
- Twitter::Configuration
- Twitter::Creatable
- Twitter::Cursor
- Twitter::DirectMessage
- Twitter::Entities
- Twitter::Entity
- Twitter::Entity::Hashtag
- Twitter::Entity::Symbol
- Twitter::Entity::URI
- Twitter::Entity::URL
- Twitter::Entity::UserMention
- Twitter::Enumerable
- Twitter::Error
- Twitter::Error::AlreadyFavorited
- Twitter::Error::AlreadyRetweeted
- Twitter::Error::BadGateway
- Twitter::Error::BadRequest
- Twitter::Error::ClientError
- Twitter::Error::Code
- Twitter::Error::ConfigurationError
- Twitter::Error::DuplicateStatus
- Twitter::Error::Forbidden
- Twitter::Error::GatewayTimeout
- Twitter::Error::InternalServerError
- Twitter::Error::NotAcceptable
- Twitter::Error::NotFound
- Twitter::Error::RequestTimeout
- Twitter::Error::ServerError
- Twitter::Error::ServiceUnavailable
- Twitter::Error::TooManyRequests
- Twitter::Error::UnacceptableIO
- Twitter::Error::Unauthorized
- Twitter::Error::UnprocessableEntity
- Twitter::Factory
- Twitter::Geo
- Twitter::Geo::Point
- Twitter::Geo::Polygon
- Twitter::GeoFactory
- Twitter::GeoResults
- Twitter::Identity
- Twitter::Language
- Twitter::List
- Twitter::Media
- Twitter::Media::Photo
- Twitter::MediaFactory
- Twitter::Metadata
- Twitter::OEmbed
- Twitter::Place
- Twitter::Profile
- Twitter::ProfileBanner
- Twitter::REST
- Twitter::REST::API
- Twitter::REST::Client
- Twitter::REST::DirectMessages
- Twitter::REST::Favorites
- Twitter::REST::FriendsAndFollowers
- Twitter::REST::Help
- Twitter::REST::Lists
- Twitter::REST::Media
- Twitter::REST::OAuth
- Twitter::REST::PlacesAndGeo
- Twitter::REST::Request
- Twitter::REST::Request::MultipartWithFile
- Twitter::REST::Response
- Twitter::REST::Response::ParseErrorJson
- Twitter::REST::Response::ParseJson
- Twitter::REST::Response::RaiseError
- Twitter::REST::SavedSearches
- Twitter::REST::Search
- Twitter::REST::SpamReporting
- Twitter::REST::SuggestedUsers
- Twitter::REST::Timelines
- Twitter::REST::Trends
- Twitter::REST::Tweets
- Twitter::REST::Undocumented
- Twitter::REST::Users
- Twitter::REST::Utils
- Twitter::RateLimit
- Twitter::Relationship
- Twitter::Request
- Twitter::SavedSearch
- Twitter::SearchResults
- Twitter::Settings
- Twitter::Size
- Twitter::SourceUser
- Twitter::Streaming
- Twitter::Streaming::Client
- Twitter::Streaming::Connection
- Twitter::Streaming::DeletedTweet
- Twitter::Streaming::Event
- Twitter::Streaming::FriendList
- Twitter::Streaming::MessageParser
- Twitter::Streaming::Response
- Twitter::Streaming::StallWarning
- Twitter::Suggestion
- Twitter::TargetUser
- Twitter::Token
- Twitter::Trend
- Twitter::TrendResults
- Twitter::Tweet
- Twitter::User
- Twitter::Utils
- Twitter::Utils::ClassMethods
- Twitter::Version

No matching classes.

# Twitter::Base

### Attributes

attrs[R]
to_h[R]

### Public Class Methods

attr_reader(*attrs) click to toggle source

Define methods that retrieve the value from attributes

@param attrs [Array, Symbol]

    # File lib/twitter/base.rb, line 21
    def attr_reader(*attrs)
      attrs.each do |attr|
        define_attribute_method(attr)
        define_predicate_method(attr)
      end
    end

define_attribute_method(key1, klass = nil, key2 = nil) click to toggle source

Dynamically define a method for an attribute

@param key1 [Symbol] @param klass [Symbol] @param key2 [Symbol]

    # File lib/twitter/base.rb, line 85
    def define_attribute_method(key1, klass = nil, key2 = nil)
      define_method(key1) do ||
        if @attrs[key1].nil? || @attrs[key1].respond_to?(:empty?) && @attrs[key1].empty?
          NullObject.new
        else
          if klass.nil?
            @attrs[key1]
          else
            attrs = attrs_for_object(key1, key2)
            Twitter.const_get(klass).new(attrs)
          end
        end
      end
      memoize(key1)
    end

define_predicate_method(key1, key2 = key1) click to toggle source

Dynamically define a predicate method for an attribute

@param key1 [Symbol] @param key2 [Symbol]

    # File lib/twitter/base.rb, line 116
    def define_predicate_method(key1, key2 = key1)
      define_method(:"#{key1}?") do ||
        !@attrs[key2].nil? && @attrs[key2] != false && !(@attrs[key2].respond_to?(:empty?) && @attrs[key2].empty?)
      end
      memoize(:"#{key1}?")
    end

define_uri_method(key1, key2) click to toggle source

Dynamically define a method for a URI

@param key1 [Symbol] @param key2 [Symbol]

    # File lib/twitter/base.rb, line 73
    def define_uri_method(key1, key2)
      define_method(key1) do ||
        Addressable::URI.parse(@attrs[key2]) unless @attrs[key2].nil?
      end
      memoize(key1)
    end

deprecate_attribute_method(key) click to toggle source

Dynamically define a method for an attribute

@param key [Symbol]

    # File lib/twitter/base.rb, line 104
    def deprecate_attribute_method(key)
      define_method(key) do ||
        warn "#{Kernel.caller.first}: [DEPRECATION] ##{key} is deprecated. Use ##{key}? instead."
        @attrs[key]
      end
      memoize(key)
    end

display_uri_attr_reader() click to toggle source

Define display_uri attribute methods

    # File lib/twitter/base.rb, line 62
    def display_uri_attr_reader
      define_attribute_method(:display_url)
      alias_method(:display_uri, :display_url)
      define_predicate_method(:display_uri, :display_url)
      alias_method(:display_url?, :display_uri?)
    end

new(attrs = {}) click to toggle source

Initializes a new object

@param attrs [Hash] @return [Twitter::Base]

    # File lib/twitter/base.rb, line 128
    def initialize(attrs = {})
      @attrs = attrs || {}
    end

object_attr_reader(klass, key1, key2 = nil) click to toggle source

Define object methods from attributes

@param klass [Symbol] @param key1 [Symbol] @param key2 [Symbol]

    # File lib/twitter/base.rb, line 40
    def object_attr_reader(klass, key1, key2 = nil)
      define_attribute_method(key1, klass, key2)
      define_predicate_method(key1)
    end

predicate_attr_reader(*attrs) click to toggle source

    # File lib/twitter/base.rb, line 28
    def predicate_attr_reader(*attrs)
      attrs.each do |attr|
        define_predicate_method(attr)
        deprecate_attribute_method(attr)
      end
    end

uri_attr_reader(*attrs) click to toggle source

Define URI methods from attributes

@param attrs [Array, Symbol]

    # File lib/twitter/base.rb, line 48
    def uri_attr_reader(*attrs)
      attrs.each do |uri_key|
        array = uri_key.to_s.split('_')
        index = array.index('uri')
        array[index] = 'url'
        url_key = array.join('_').to_sym
        define_uri_method(uri_key, url_key)
        alias_method(url_key, uri_key)
        define_predicate_method(uri_key, url_key)
        alias_method(:"#{url_key}?", :"#{uri_key}?")
      end
    end

### Public Instance Methods

[](method) click to toggle source

Fetches an attribute of an object using hash notation

@param method [String, Symbol] Message to send to the object

    # File lib/twitter/base.rb, line 135
    def [](method)
      warn "#{Kernel.caller.first}: [DEPRECATION] #[#{method.inspect}] is deprecated. Use ##{method} to fetch the value."
      send(method.to_sym)
    rescue NoMethodError
      nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.