Skip to content

Commit

Permalink
Make Twitter::Base#[] behave more like a hash
Browse files Browse the repository at this point in the history
Hat-tip: @laserlemon
  • Loading branch information
sferik committed Nov 9, 2011
1 parent 943f509 commit acc1c79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def initialize(attrs={})
# @param method [String, Symbol] Message to send to the object
def [](method)
self.__send__(method.to_sym)
rescue NoMethodError
nil
end

end
Expand Down
4 changes: 4 additions & 0 deletions spec/twitter/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
it "should be able to call methods using [] with string" do
@base['object_id'].should be_an Integer
end
it "should return nil for missing method" do
@base[:foo].should be_nil
@base['foo'].should be_nil
end
end

describe "#to_hash" do
Expand Down

0 comments on commit acc1c79

Please sign in to comment.