プログラムにおいて、スタックとは関数が呼び出した際に積まれ、その関数が実行終了したらポップするものだと思っています。スタックトレースとは現在のスタックの積まれているもの、メソッドの呼び出し順を確認するために使うかと思います。
rubyのgemであるtwitterのソースコードを読み始めました。ソースコードリーディングにはpryがいいとのことで、これを使っていこうと思います。今回は、client.update
メソッドにbinding.pry
を記述して追っていくつもりでした。update
に入り、show-stack
を実行するとupdate
が積まれているのがわかります。ここでupdate
の中で呼びだされているupdate!
メソッドにstep
して入ってみると、show-stack
してもスタックが表示されなくなりました。No caller stack available!
と表示されます。
私の考えではupdate
の上にupdate!
が積まれてるかと思いましたが、そうではなかったみたいです。上記のスタックに関する知識が間違っているのでしょうか?それとも別の問題があるのでしょうか?
他にもソースコードリーディングに役立つものがあれば教えて下さい。
ご回答、よろしくお願い致します。
環境
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
Pry version 0.10.2 on Ruby 2.2.2
ruby
1# Gemfile 2source 'http://rubygems.org' 3 4gem 'pry' 5gem 'pry-byebug' 6gem 'pry-stack_explorer' 7gem 'activesupport' 8gem 'twitter'
pryでの実行ログ
ruby
1# トークンは実際に自分のを入れています。 2client = Twitter::REST::Client.new do |config| 3 config.consumer_key = "YOUR_CONSUMER_KEY" 4 config.consumer_secret = "YOUR_CONSUMER_SECRET" 5 config.access_token = "YOUR_ACCESS_TOKEN" 6 config.access_token_secret = "YOUR_ACCESS_SECRET" 7end 8 9show-stack 10Showing all accessible frames in stack (5 in total): 11-- 12=> #0 __pry__ <self.__pry__(UNKNOWN) (undefined method)> 13 #1 [block] block in parse_options <Pry::CLI.parse_options(args=?)> 14 #2 [method] parse_options <Pry::CLI.parse_options(args=?)> 15 #3 [top] <top (required)> 16 #4 [main] <main> 17 18From: /Users/mitsuru/.rbenv/versions/2.2.2/gemsets/mygemsets/gems/twitter-5.15.0/lib/twitter/rest/tweets.rb @ line 129 Twitter::REST::Tweets#update: 19client.update("hello") 20 127: def update(status, options = {}) 21 128: binding.pry 22 => 129: update!(status, options) 23 130: rescue Twitter::Error::DuplicateStatus 24 131: user_timeline(:count => 1).first 25 132: end 26 27show-stack 28Showing all accessible frames in stack (5 in total): 29-- 30=> #0 update <Twitter::REST::Tweets#update(status, options=?)> 31 #1 [block] block in parse_options <Pry::CLI.parse_options(args=?)> 32 #2 [method] parse_options <Pry::CLI.parse_options(args=?)> 33 #3 [top] <top (required)> 34 #4 [main] <main> 35[2] pry(#<Twitter::REST::Client>)> step 36 37step 38From: /Users/mitsuru/.rbenv/versions/2.2.2/gemsets/mygemsets/gems/twitter-5.15.0/lib/twitter/rest/tweets.rb @ line 156 Twitter::REST::Tweets#update!: 39 155: def update!(status, options = {}) 40 => 156: hash = options.dup 41 157: hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil? 42 158: hash[:place_id] = hash.delete(:place).woeid unless hash[:place].nil? 43 159: perform_post_with_object('/1.1/statuses/update.json', hash.merge(:status => status), Twitter::Tweet) 44 160: end 45 46show-stack 47No caller stack available! 48
あなたの回答
tips
プレビュー