lib/twitter/base.rb in twitter-4.3.0 vs lib/twitter/base.rb in twitter-4.4.0

- old
+ new

@@ -1,24 +1,26 @@ require 'twitter/core_ext/kernel' require 'twitter/error/identity_map_key_error' module Twitter class Base - attr_reader :attrs - alias to_hash attrs - # Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key # # @param attrs [Array, Set, Symbol] def self.attr_reader(*attrs) - attrs.each do |attribute| - class_eval do + mod = Module.new do + attrs.each do |attribute| define_method attribute do @attrs[attribute.to_sym] end + define_method "#{attribute}?" do + !!@attrs[attribute.to_sym] + end end end + const_set(:Attributes, mod) + include mod end # return [Twitter::IdentityMap] def self.identity_map return unless Twitter.identity_map @@ -85,9 +87,17 @@ def [](method) send(method.to_sym) rescue NoMethodError nil end + + # Retrieve the attributes of an object + # + # @return [Hash] + def attrs + @attrs + end + alias to_hash attrs # Update the attributes of an object # # @param attrs [Hash] # @return [Twitter::Base]