ä¹
ã
ã®æ´æ°ã
ããã¡ãã£ã¨çã¾ãã«ãªããªãã¨ã
ä»æ¥ã¯ãShibuya.rbã«åå ãã¦ãã¾ããã
ä»åã®ã¡ã¤ã³ã®ãã¼ãã¯Rackããã«ã¦ã§ã¢ãèªãã£ã¦ãã¨ã§ã
åèªãèªã¿ããããã«ãé¸ãã§ããã¼ãã«ã«åããã¦ã
ããããèªãã§ã¿ãã¨ããæãã§ãã
ç§ã¯ãRack::Auth::Basicãèªãã§ã¾ããã
ã·ã³ãã«ã§ããã«å®çµãã¦ããã®ã§èªã¿ãããæãã ã£ãã¨æãã¾ãã
ç§ã®ãã¼ãã«ã§ã¯ãçMacã ã£ãã®ã§ãç»é¢å
±æã使ã£ã¦ã
åãç»é¢ã§ä¸ç·ã«ã½ã¼ã¹ãè¦ã¦ãé ã«è¿½ã£ã¦ããã¨ããæãã§ãèªãã§ã¿ã¾ããã
ãã¼ãã«ãã¨ã«ã¢ãã¿ãããã°ãä¸ç·ã«èªãæã«ã¯ããªãæããã ãããã©ã
ä¸ç¤ã«LTæ ããã£ãã®ã§ãçªçºã§è³æãç¡ãã«Pryã«ã¤ãã¦è©±ãããã¦ãããã¾ããã
ãã¼ããã½ã¼ã¹ã³ã¼ããªã¼ãã£ã³ã°ã ã£ãã®ã§ãã
æè¿ãã½ã¼ã¹ã³ã¼ããèªãã ããRailsã§specæ¸ãããããæã«ã
ããã¯ä¾¿å©ã ï¼ã¨æãããã¨ã話ãããæ©ä¼ã ã¨æã£ãããã§ãã
ã¨ããããã§ããã£ããã¨è©±ããå
容ã«ã¤ãã¦æ¸ãã¦ã¿ã¾ãã
pryãèµ·åããããã¾ãã¯helpã¨æã£ã¦ã¿ã¾ãããã
ããããã¨ã³ãã³ããåºã¦ãã¾ãã
ãã®ä¸ã§ãã¡ã¤ã³ã§æ´»ç¨ãããã³ãã³ãã¯ä»¥ä¸ã§ãã
- cd: å¼æ°ã§æå®ãããªãã¸ã§ã¯ãã®ã³ã³ããã¹ãã«ç§»åãã
- ls: èªåãä»å± ãã³ã³ããã¹ãã§åç §ã§ããã¡ã½ãããå¤æ°ãä¸è¦§ã§è¦ã
- show-method: å¼æ°ã§æå®ããã¡ã½ããã®å®ç¾©ããã¦ããã³ã¼ããè¦ãã(ãã¡ã¤ã«ãè¡æ°ãåãã)
- edit: ã¨ãã£ã¿ã§pryã«å ¥åããã³ã¼ããè¨è¿°ã§ããã
- edit-method: å¼æ°ã§æå®ããã¡ã½ãããå®ç¾©ãã¦ãããã¡ã¤ã«ãã¨ãã£ã¿ã§éãã
cdã¨lsã¯ãããªæãã§ä½¿ãã¾ãã
[5] pry(main)> a=[] => [] [6] pry(main)> cd a [7] pry(#<Array>):1> ls Enumerable#methods: all? any? chunk collect_concat detect each_cons each_entry each_slice each_with_index each_with_object entries find find_all flat_map grep group_by inject max max_by member? min min_by minmax minmax_by none? one? partition reduce slice_before sort_by Array#methods: & * + - << <=> == [] []= assoc at clear collect collect! combination compact compact! concat count cycle delete delete_at delete_if drop drop_while each each_index empty? eql? fetch fill find_index first flatten flatten! frozen? hash include? index insert inspect join keep_if last length map map! pack permutation place pop pretty_print pretty_print_cycle product push rassoc reject reject! repeated_combination repeated_permutation replace reverse reverse! reverse_each rindex rotate rotate! sample select select! shelljoin shift shuffle shuffle! size slice slice! sort sort! sort_by! take take_while to_a to_ary to_s transpose uniq uniq! unshift values_at zip | self.methods: __binding_impl__ locals: _ _dir_ _ex_ _file_ _in_ _out_ _pry_
(å®éã«ã¯æ»ãå¤ã«ã¯è²ãä»ãã¦ã¾ãã)
ãããªæãã§ãé
åã®ã¤ã³ã¹ã¿ã³ã¹ã«ã³ã³ããã¹ãã«å
¥ã£ã¦lsãå®è¡ããã¨ã
é
åãæã£ã¦ããã¤ã³ã¹ã¿ã³ã¹ã¡ã½ããããã¤ã³ã¯ã«ã¼ããã¦ããã¢ã¸ã¥ã¼ã«ã§å®ç¾©ããã¦ããã¡ã½ããã
ä»ã«ã¤ã³ã¹ã¿ã³ã¹å¤æ°ãªãããåç
§ã§ãã¾ãã
ã¾ããls -vã使ãã¨ãã¹ã¼ãã¼ã¯ã©ã¹ãå«ãã¦ã¡ã½ãããåç
§ã§ãã¾ãã
irbã§ãpp hoge.methods.sortã¨ããããã¨ãããã¨æãã¾ããã
pryã®ã³ãã³ãã¯å®ç¾©ããã¦ããã³ã³ããã¹ããã¨ã«ã¾ã¨ã¾ã£ã¦è¡¨ç¤ºããããããé常ã«è¦ãããã¨ãããããæãã§ãã
show-methodã¯ãããªæãã§ä½¿ãã¾ãã
[3] pry(User):1> show-method database_authenticatable From: /Users/joker/pasokara_player_rails3/vendor/bundle/ruby/1.9.1/gems/devise-2.0.0/lib/devise/schema.rb @ line 16: Number of lines: 8 Owner: Devise::Schema Visibility: public def database_authenticatable(options={}) null = options[:null] || false default = options.key?(:default) ? options[:default] : ("" if null == false) include_email = !respond_to?(:authentication_keys) || self.authentication_keys.include?(:email) apply_devise_schema :email, String, :null => null, :default => default if include_email apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128 end
ãã®ããã«ãã¡ã½ãããå®ç¾©ããã¦ãããã¡ã¤ã«ãè¡æ°ã¨å®ç¾©å
容ãåç
§ã§ãã¾ãã
ããã¯ãMongoidãã¤ã³ã¯ã«ã¼ããã¦ããUserã¯ã©ã¹ã«å
¥ããdeviseã®èªè¨¼å®ç¾©ãshow-methodããã¨ããã§ãã
ãã®åç
§çµæã ãè¦ã¦ãå
容ãå
¨é¨åãããã¨ã¯ãã¾ãç¡ãã¨æãã¾ããã
ãã£ããã¨ããåä½ã¤ã¡ã¼ã¸ã®ææ¡ã¯ã§ãã¾ããã
å®ç¾©å ´æãæ確ã«åããã®ã§ãç´°ããç¥ãããæã¯ãã³ã¼ããèªãèµ·ç¹ã¨ãã¦æ´»ç¨ã§ãã¾ãã
ããã§ãedit-methodã使ã£ã¦ãdatabase_authenticatableãå¼æ°ã«æ¸¡ãã¨ã
ç°å¢å¤æ°EDITORã§æå®ãã¦ããã¨ãã£ã¿ã§ãã®å®ç¾©å ´æãéããã¨ãã§ãã¾ãã
ãã®ã¾ã¾ä»è¿ãèªãã§ããããããã®ã¾ã¾éããã°ãpryã«æ»ã£ã¦ãããã¨ãã§ãã¾ãã
editã¯pryã§å®è¡ããrubyã®ã³ã¼ãããã®ã¾ã¾ã¨ãã£ã¿ã§è¨è¿°ãã¦å¦çã§ãããã®ã§ã
irbã«ãããinteractie_editorã¨åæ§ãªã®ã§ã詳ãã説æã¯çãã¾ãã
ããã ãã§ãããªã便å©ãªã®ã§ããã
pryã«ã¯æ´ã«å¼·åãªæ©è½ãããã¾ãã
ä»åãRackããã«ã¦ã§ã¢ãèªãéã«ãæ´»ç¨ãã¾ãããã
ã³ã¼ãä¸ã«binding.pryã¨è¨è¿°ãããã¨ã§ã
ãã®ã¿ã¤ãã³ã°ã§ã¤ã³ã¿ã©ã¯ãã£ãã¢ã¼ãã«ç§»è¡ãã¦
pryä¸ã§ã³ã¼ããå®è¡ã§ããããã«ãªãã¾ãã
ä»åã ã¨ãããªæãã
require "rubygems" require "rack" require "pry" class Hello def call(env) binding.pry [200, {"Content-Type" => "text/plain"}, ["Hello World"]] end end use Rack::Auth::Basic do |user, pass| user == "test" && pass == "password" end run Hello.new
rackupãã¦ã¢ã¯ã»ã¹ãã¦ã¿ãã¨ãããªãã¾ãã
[2012-02-16 02:02:52] INFO WEBrick 1.3.1 [2012-02-16 02:02:52] INFO ruby 1.9.3 (2011-10-30) [x86_64-darwin10.8.0] [2012-02-16 02:02:52] INFO WEBrick::HTTPServer#start: pid=76976 port=9292 From: /Users/joker/temp/config.ru @ line 8 in Hello#call: 3: require "pry" 4: 5: class Hello 6: def call(env) 7: binding.pry => 8: [200, {"Content-Type" => "text/plain"}, ["Hello World"]] 9: end 10: end 11: 12: use Rack::Auth::Basic do |user, pass| 13: user == "test" && pass == "password" [1] pry(#<Hello>)>
envã¨æã£ã¦ã¿ãã
[2] pry(#<Hello>)> env => {"GATEWAY_INTERFACE"=>"CGI/1.1", "PATH_INFO"=>"/", "QUERY_STRING"=>"", "REMOTE_ADDR"=>"127.0.0.1", "REMOTE_HOST"=>"localhost", "REQUEST_METHOD"=>"GET", "REQUEST_URI"=>"http://localhost:9292/", "SCRIPT_NAME"=>"", "SERVER_NAME"=>"localhost", "SERVER_PORT"=>"9292", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.9.3/2011-10-30)", "HTTP_HOST"=>"localhost:9292", "HTTP_USER_AGENT"=> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1", "HTTP_ACCEPT"=> "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "HTTP_ACCEPT_LANGUAGE"=>"ja,en-us;q=0.7,en;q=0.3", "HTTP_ACCEPT_ENCODING"=>"gzip, deflate", "HTTP_ACCEPT_CHARSET"=>"Shift_JIS,utf-8;q=0.7,*;q=0.7", "HTTP_CONNECTION"=>"keep-alive", "HTTP_AUTHORIZATION"=>"Basic dGVzdDpwYXNzd29yZA==", "HTTP_CACHE_CONTROL"=>"max-age=0", "rack.version"=>[1, 1], "rack.input"=> #<Rack::Lint::InputWrapper:0x00000100b48920 @input=#<StringIO:0x00000100b5e400>>, "rack.errors"=> #<Rack::Lint::ErrorWrapper:0x00000100b48880 @error=#<IO:<STDERR>>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "rack.url_scheme"=>"http", "HTTP_VERSION"=>"HTTP/1.1", "REQUEST_PATH"=>"/", "REMOTE_USER"=>"test"}
Rack::Auth::Basicã§ã¯ãHTTP_AUTHORIZATIONãããããã
credentialsãåå¾ãã¦ããã¨ããè¨è¿°ãããã¾ããã
ããããå
容ã確èªãã¦ã¿ããã£ã¦ãã¨ã§ã
ã¢ã¯ã»ã¹ã®éä¸ã§å®è¡ãæ¢ãã¦ãenvãè¦ããã¨ããå½¢ã§æ´»ç¨ãã¦ã¿ã¾ããã
exitãã¦pryãçµäºããã¨ç¶ãã®ã³ã¼ããæµãã¦ãã¾ãã
ã¡ãªã¿ã«ãjugyoãããä½ã£ããir_bã¨ããgemã§irbä¸ã§ãåããã¨ãã§ãã¾ãã
ãã®å ´åã¯ãbinding.pryã§ã¯ãªããir bã¨ããå½¢ã§è¨è¿°ãã¾ãã
åãã³ã¼ãã§pryãèµ·åã§ããããã«ãpryç¨ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ãç¨æãã¦ããã¦ãã¾ãã
(jugyo/ir_b - GitHub https://github.com/jugyo/ir_b)
ä»ã«ãrspecã®ã³ã¼ãã®ä¸ã«binding.pryãä»è¾¼ãã¨ã以ä¸ã®ãããªãã¨ãåºæ¥ã¾ãã
[1] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_2>)> subject => #<Repository _id: 4f3be74c91ea182d9e00000a, _type: nil, url: "https://github.com/joker1007/pasokara_player3", username: "joker1007", name: "pasokara_player3"> [2] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_2>)> subject.username.should eq("joker1007") => true [3] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_2>)> subject.username.should eq("joker") RSpec::Expectations::ExpectationNotMetError: expected: "joker" got: "joker1007" (compared using ==) from /Users/joker/gemfilestats/vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.8.0/lib/rspec/expectations/fail_with.rb:32:in `fail_with' [4] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_2>)>
subjectã«ã¯ãMongoidã®ãªãã¸ã§ã¯ããå
¥ã£ã¦ãã¾ãã
ãã®ãªãã¸ã§ã¯ãã«å¯¾ãã¦ãå³åº§ã«shouldãå¼ã³åºãããã¹ãã³ã¼ãã®åãã確èªã§ãã¾ãã
ã¾ãããã®ã³ã³ããã¹ãã§ä½¿ããã¡ã½ããã«å¯¾ãã¦è£å®ãå¹ãããã
have_ã¨æã£ã¦ãTABãæ¼ãã¨ããããªæãã§ãããã£ã¼ãè¦ããããã¾ãã
[19] pry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_2>)> subject.should have have have_and_belong_to_many have_at_least have_at_most have_exactly have_field have_fields have_many have_many_related have_one have_one_related have_instance_method
rspecã対話çã«å®è¡ãããªããa_matsudaããä½ã®interactive_rspecãªãããããã¾ãã
irbã§ã·ã³ãã«ã«å®è¡ãããªãããã¡ãã®æ¹ãè¯ãã§ãããã
(amatsuda/interactive_rspec - GitHub https://github.com/amatsuda/interactive_rspec)
ä»åã話ããäºã¯ãirbã®æ¡å¼µè¨å®ããã£ãããæ¡å¼µããgemãå°å
¥ãããã¨ã§ã
ããç¨åº¦ãirbã§ãå®ç¾ãããã¨ãå¯è½ã ã£ãããã¾ãã
è²ä»ããããã¨ãã£ã¿ã§ç·¨éããããå®è¡éä¸ã§æ¢ãããã
pryã¯è¨å®ç¡ãã§ããããã£ãæ©è½ãããã«å©ç¨ã§ããç¹ã¯é常ã«ãããããã¨æãã¾ããã
cdã«ããã³ã³ããã¹ãã®ç§»åãls, show-methodã«ããåç
§ã¯é常ã«å¼·åã§ãããã¯irbã«ã¯ç¡ãæ©è½ã§ãã
ãããã®æ©è½ã¯ãã¡ãã£ã¨ããæã«è¦ãã¦ããã¨åã便å©æãå³ããã¾ãã
cd, ls, show-method, binding.pry, ã¨ããããããã ãè¦ãã¦ããã¾ãããã
ä¸æ¹ã§ãruby-debugçã¨éã£ã¦ãããã¬ã§ã¯ç¡ãããã
ã¹ãããå®è¡ããã¬ã¼ã¯ãã¤ã³ãã®æå®ãªã©ã¯åºæ¥ã¾ããã
ä¸é£ã®ããã¼ãæ¤è¨¼ãããæã¯ãruby-debugçãæ´»ç¨ããå ´åã«ãã£ã¦ä½¿ãåãã¦ããã®ãè¯ãã¨æãã¾ãã
Shibuya.rbã§ã¯ãã·ã§ã«ãç´æ¥æä½ãã¦ãã¢ããªããçºè¡¨ã¨ããå½¢ã ã£ãã®ã§ã
çºè¡¨å
容ã«ããã¤ãä»ãå ãã¦ãã¾ã¨ãã¦ã¿ã¾ããã
å
¬å¼ã®wikiã«ã¯çµæ§è²ã
æ¸ãã¦ãããã§ããã
æ´»ç¨æ³ã«ã¤ãã¦ã¯ãæ¥æ¬èªã®æ
å ±ã£ã¦ããã¾ãç¡ãã£ããããªæ°ããã¾ãã
ãã®è¨äºã誰ãã®åèã«ãªãã°å¹¸ãã§ãã
追è¨:
æ¸ããå¾ã§ãTwitterã§æ
å ±ãé ãã¦ãruby-debugã«pryã³ãã³ãã追å ã§ãããruby-debug-pryãªããã®ããããããã§ãã
å
¨ç¶ç¥ããªãã£ããã¾ã ã¾ã 奥ãæ·±ãã§ããã
(AndrewO/ruby-debug-pry - GitHub https://github.com/AndrewO/ruby-debug-pry)
å¾ãã¹ã¿ãã¯ã追ã£æãã¦ç§»åã§ããpry-stack_explorerã¨ãããã©ã°ã¤ã³ãããã¾ãã
ãã£ã¡ã¯ç¥ã£ã¦ããã§ãããã¾ã å©ç¨ãããã¨ãç¡ããããä»åã¯è©±ã«å
¥ãã¦ã¾ããã§ããã
ã¤ãã§ã«ãã¡ããè²¼ã£ã¦ããã¾ãã
(banister/pry-stack_explorer - GitHub https://github.com/banister/pry-stack_explorer)
ãããä»åº¦ä½¿ã£ã¦ã¿ããã
Thanks! @Kirika_K2