Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move Hash#except and Hash#except! into Twitter::Exceptable module

  • Loading branch information...
commit 0a8591efce268119e29623317382a1f2de2d0aa6 1 parent 2e8bfa3
@sferik authored
View
1  lib/twitter/api/utils.rb
@@ -1,5 +1,4 @@
require 'twitter/core_ext/enumerable'
-require 'twitter/core_ext/hash'
require 'twitter/core_ext/kernel'
require 'twitter/cursor'
require 'twitter/user'
View
20 lib/twitter/core_ext/hash.rb
@@ -1,20 +0,0 @@
-class Hash
-
- # Return a hash that includes everything but the given keys.
- #
- # @param keys [Array, Set]
- # @return [Hash]
- def except(*keys)
- self.dup.except!(*keys)
- end unless method_defined?(:except)
-
- # Replaces the hash without the given keys.
- #
- # @param keys [Array, Set]
- # @return [Hash]
- def except!(*keys)
- keys.each{|key| delete(key)}
- self
- end unless method_defined?(:except!)
-
-end
View
24 lib/twitter/exceptable.rb
@@ -0,0 +1,24 @@
+module Twitter
+ module Exceptable
+
+ # Return a hash that includes everything but the given keys.
+ #
+ # @param hash [Hash]
+ # @param key [Symbol]
+ # @return [Hash]
+ def except(hash, key)
+ except!(hash.dup, key)
+ end
+
+ # Replaces the hash without the given keys.
+ #
+ # @param hash [Hash]
+ # @param key [Symbol]
+ # @return [Hash]
+ def except!(hash, key)
+ hash.delete(key)
+ hash
+ end
+
+ end
+end
View
5 lib/twitter/tweet.rb
@@ -1,8 +1,8 @@
-require 'twitter/core_ext/hash'
require 'twitter/creatable'
require 'twitter/entity/hashtag'
require 'twitter/entity/url'
require 'twitter/entity/user_mention'
+require 'twitter/exceptable'
require 'twitter/geo_factory'
require 'twitter/identity'
require 'twitter/media_factory'
@@ -13,6 +13,7 @@
module Twitter
class Tweet < Twitter::Identity
include Twitter::Creatable
+ include Twitter::Exceptable
attr_reader :favorited, :favoriters, :from_user_id, :from_user_name,
:in_reply_to_screen_name, :in_reply_to_attrs_id, :in_reply_to_status_id,
:in_reply_to_user_id, :iso_language_code, :profile_image_url,
@@ -121,7 +122,7 @@ def urls
# @return [Twitter::User]
def user
- @user ||= Twitter::User.fetch_or_new(@attrs.dup[:user].merge(:status => @attrs.except(:user))) if user?
+ @user ||= Twitter::User.fetch_or_new(@attrs.dup[:user].merge(:status => except(@attrs, :user))) if user?
end
# @note Must include entities in your request for this method to work
View
5 lib/twitter/user.rb
@@ -1,12 +1,13 @@
require 'twitter/basic_user'
-require 'twitter/core_ext/hash'
require 'twitter/creatable'
+require 'twitter/exceptable'
require 'twitter/tweet'
module Twitter
class User < Twitter::BasicUser
PROFILE_IMAGE_SUFFIX_REGEX = /_normal(\.gif|\.jpe?g|\.png)$/
include Twitter::Creatable
+ include Twitter::Exceptable
attr_reader :connections, :contributors_enabled, :default_profile,
:default_profile_image, :description, :favourites_count,
:follow_request_sent, :followers_count, :friends_count, :geo_enabled,
@@ -93,7 +94,7 @@ def profile_image_url?
# @return [Twitter::Tweet]
def status
- @status ||= Twitter::Tweet.fetch_or_new(@attrs.dup[:status].merge(:user => @attrs.except(:status))) if status?
+ @status ||= Twitter::Tweet.fetch_or_new(@attrs.dup[:status].merge(:user => except(@attrs, :status))) if status?
end
def status?
Please sign in to comment.
Something went wrong with that request. Please try again.