$30 off During Our Annual Pro Sale. View Details »

頻出pryコマンド

 頻出pryコマンド

Railsプロジェクトでよく使うpryコマンド

Atsushi Uchida (utwang)

June 10, 2015
Tweet

More Decks by Atsushi Uchida (utwang)

Other Decks in Programming

Transcript

  1. සग़PryίϚϯυ ʙշదdebugʙ

  2. ίʔσΟϯάʹඅ΍࣌ؒ͢ ௐ΂Δɾߟ͑Δ ίʔυ/ςετΛॻ͘ σόοά͢Δ

  3. σόοάΛิॿ͢Δπʔϧ Ruby irb, pry JavaScript Developer Tool, Firebug

  4. pryͳ͠ͷruby։ൃ͸ ߟ͑ΒΕͳ͍ ߴػೳ͗ͯ͢ԿΛ࢖͑͹͍͍ͷ͔ʁ ·ͣΑ͘࢖͏ίϚϯυΛ֮͑Δ

  5. ls ݱࡏͷcontextͷ಺༰Λ֬ೝͰ͖Δɻ ͜ͷΦϒδΣΫτͲ͏͍͏ϝιου͕͋Δ ͔Λௐ΂Δͷʹศར [1] pry > user = User.first

    [2] pry > cd user [3] pry > ls #=> userͷlocalม਺ɺϝιουͳͲΛࢀরͰ͖Δ # cd͢Δલʹls userͰ΋ಉ͡ # ΦϓγϣϯΛࢦఆ͢ΔͱߜࠐՄೳ [4] pry > ls -m (ΠϯελϯεϝιουͷΈදࣔ) [5] pry > ls -m -G before (beforeΛؚΉΠϯελϯεϝιουͷΈදࣔ)
  6. whereami σόοάதʹࠓɺͲ͜ʹ͍Δ͔Θ͔Βͳ͘ͳͬ ͨͱ͖ʹศརɻʢҾ਺͸લޙͷදࣔߦ਺ʣ [4] pry(#<User>)> whereami 5 134: update_by_facebook_oauth(auth) 135:

    true 136: end 137: 138: def uncomplete_facebook_logined? => 139: has_oauth_info? && tel.blank? 140: end 141: 142: def send_confirmation_instructions 143: unless @raw_confirmation_token 144: generate_confirmation_token!
  7. hist ίϚϯυͷཤྺΛදࣔ͢Δɻ աڈͷίϚϯυΛ·ͱΊ࣮ͯߦ͍ͨ͠ͱ͖ʹར༻ɻ [46] pry(main)> users.map do |u| [46] pry(main)*

    name = u.name [46] pry(main)* tel = u.tel [46] pry(main)* "#{name} {tel}" [46] pry(main)* end [47] pry(main)> hist -T 10 -n x = 1 y = 2 x + y x * y users = User.all users.map do |u| name = u.name tel = u.tel "#{name} {tel}" end # ↑ඞཁͳͱ͜ΖΛίϐϖ
  8. show-xxx σόοάதʹίʔυΛݟ͍ͨͱ͖ɺϞσϧͷ಺༰ Λ஌Γ͍ͨͱ͖ͳͲ [1] pry > user = User.first [2]

    pry > show-source user #=> UserͷίʔυΛදࣔ [1] pry > show-model User #=> UserϞσϧͷଐੑ΍ؔ࿈Λදࣔ [1] pry > show-method User#has_oauth_info? #=> ϝιουͷ࣮૷Λදࣔ … def has_oauth_info? uid.present? && provider.present? end [1] pry > show-routes
  9. wtf? & ex What the Fuck? ErrorൃੜޙʹόοΫτϨʔεΛݟΔ [82] pry(main)> wtf?

    Exception: NoMethodError: undefined method `provider' for 100000000:Fixnum -- 0: /Users/x2x2tone/Projects/smart_yoyaku/ebis/app/models/ebis/user.rb:124:in `update_by_facebook_oauth' 1: /Users/x2x2tone/Projects/smart_yoyaku/ebis/app/models/ebis/user.rb:134:in `connect_to_facebook_oauth' 2: (pry):28:in `<main>' 3: /Users/x2x2tone/Projects/smart_yoyaku/ebis/vendor/bundle/ruby/2.1.0/gems/ pry-0.9.12.6/lib/pry/pry_instance.rb:328:in `eval' 4: /Users/x2x2tone/Projects/smart_yoyaku/ebis/vendor/bundle/ruby/2.1.0/gems/ pry-0.9.12.6/lib/pry/pry_instance.rb:328:in `evaluate_ruby' [82] pry(main)> cat —ex 1 132: 133: def connect_to_facebook_oauth(auth) => 134: update_by_facebook_oauth(auth) 135: true 136: end # wtf?Ͱදࣔͨ͠όοΫτϨʔεͷ൪߸ͷίʔυΛදࣔ
  10. shellίϚϯυ ͪΐͬͱshell͞ΘΓ͍ͨͱ͖ .[shellίϚϯυ] shell-mode [99] pry(main)> .ls config application.rb compass.rb

    environment.rb initializers routes.rb settings sitemap.rb boot.rb database.yml environments locales schedule.rb settings.local.yml breadcrumbs.rb database.yml.sample events.rb newrelic.yml secrets.yml settings.yml