chess_engine 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +21 -0
- data/README.md +26 -0
- data/chess_engine.gemspec +14 -0
- data/lib/chess_engine/board.rb +95 -0
- data/lib/chess_engine/cli.rb +105 -0
- data/lib/chess_engine/game.rb +148 -0
- data/lib/chess_engine/input.rb +19 -0
- data/lib/chess_engine/move.rb +35 -0
- data/lib/chess_engine/piece.rb +97 -0
- data/lib/chess_engine/validator.rb +87 -0
- data/lib/chess_engine.rb +1 -0
- data/spec/board_spec.rb +70 -0
- data/spec/game_helper.rb +5 -0
- data/spec/game_spec.rb +79 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/validator_spec.rb +26 -0
- data/vendor/bundle/bin/coderay +27 -0
- data/vendor/bundle/bin/pry +27 -0
- data/vendor/bundle/cache/coderay-1.1.2.gem +0 -0
- data/vendor/bundle/cache/colorize-0.8.1.gem +0 -0
- data/vendor/bundle/cache/method_source-0.9.2.gem +0 -0
- data/vendor/bundle/cache/pry-0.12.2.gem +0 -0
- data/vendor/bundle/cache/rb-readline-0.5.5.gem +0 -0
- data/vendor/bundle/gems/coderay-1.1.2/MIT-LICENSE +22 -0
- data/vendor/bundle/gems/coderay-1.1.2/README_INDEX.rdoc +123 -0
- data/vendor/bundle/gems/coderay-1.1.2/bin/coderay +215 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/duo.rb +81 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/_map.rb +17 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/comment_filter.rb +25 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/count.rb +39 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug.rb +49 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/debug_lint.rb +63 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/div.rb +23 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/encoder.rb +190 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/filter.rb +58 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/css.rb +65 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/numbering.rb +108 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html/output.rb +166 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/html.rb +333 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/json.rb +83 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lines_of_code.rb +45 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/lint.rb +59 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/null.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/page.rb +24 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/span.rb +23 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/statistic.rb +95 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/terminal.rb +195 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/text.rb +46 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/token_kind_filter.rb +111 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/xml.rb +72 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders/yaml.rb +50 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/encoders.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/for_redcloth.rb +95 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/file_type.rb +151 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin.rb +55 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/plugin_host.rb +221 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/helpers/word_list.rb +72 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/_map.rb +24 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/c.rb +189 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/clojure.rb +217 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/cpp.rb +217 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/css.rb +196 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/debug.rb +75 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/delphi.rb +144 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/diff.rb +221 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/erb.rb +81 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/go.rb +208 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/groovy.rb +268 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/haml.rb +168 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/html.rb +275 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java/builtin_types.rb +421 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java.rb +174 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/java_script.rb +237 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/json.rb +98 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/lua.rb +280 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/php.rb +527 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/python.rb +287 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/raydebug.rb +75 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/patterns.rb +178 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby/string_state.rb +79 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/ruby.rb +477 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sass.rb +232 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/scanner.rb +337 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/sql.rb +169 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/taskpaper.rb +36 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/text.rb +26 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/xml.rb +17 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners/yaml.rb +140 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/scanners.rb +27 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/_map.rb +7 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/alpha.rb +153 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles/style.rb +18 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/styles.rb +15 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/token_kinds.rb +85 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens.rb +161 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/tokens_proxy.rb +55 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay/version.rb +3 -0
- data/vendor/bundle/gems/coderay-1.1.2/lib/coderay.rb +284 -0
- data/vendor/bundle/gems/colorize-0.8.1/CHANGELOG +65 -0
- data/vendor/bundle/gems/colorize-0.8.1/LICENSE +339 -0
- data/vendor/bundle/gems/colorize-0.8.1/README.md +105 -0
- data/vendor/bundle/gems/colorize-0.8.1/Rakefile +13 -0
- data/vendor/bundle/gems/colorize-0.8.1/colorize.gemspec +36 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/class_methods.rb +120 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize/instance_methods.rb +132 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorize.rb +12 -0
- data/vendor/bundle/gems/colorize-0.8.1/lib/colorized_string.rb +19 -0
- data/vendor/bundle/gems/colorize-0.8.1/test/test_colorize.rb +164 -0
- data/vendor/bundle/gems/method_source-0.9.2/Gemfile +2 -0
- data/vendor/bundle/gems/method_source-0.9.2/LICENSE +25 -0
- data/vendor/bundle/gems/method_source-0.9.2/README.markdown +91 -0
- data/vendor/bundle/gems/method_source-0.9.2/Rakefile +81 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/code_helpers.rb +154 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/source_location.rb +138 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source/version.rb +3 -0
- data/vendor/bundle/gems/method_source-0.9.2/lib/method_source.rb +141 -0
- data/vendor/bundle/gems/method_source-0.9.2/method_source.gemspec +35 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/method_source/code_helpers_spec.rb +43 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/method_source_spec.rb +143 -0
- data/vendor/bundle/gems/method_source-0.9.2/spec/spec_helper.rb +101 -0
- data/vendor/bundle/gems/pry-0.12.2/CHANGELOG.md +953 -0
- data/vendor/bundle/gems/pry-0.12.2/LICENSE +25 -0
- data/vendor/bundle/gems/pry-0.12.2/README.md +390 -0
- data/vendor/bundle/gems/pry-0.12.2/bin/pry +8 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/basic_object.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/cli.rb +218 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_file.rb +110 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/code_range.rb +71 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code/loc.rb +98 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code.rb +353 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/code_object.rb +195 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/color_printer.rb +65 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/command.rb +723 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/command_set.rb +415 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/amend_line.rb +98 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang.rb +20 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/bang_pry.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/exception_formatter.rb +79 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/file_formatter.rb +71 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cat.rb +63 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/cd.rb +41 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_inspector.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/clear_screen.rb +14 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/code_collector.rb +167 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disable_pry.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/disabled_commands.rb +2 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/easter_eggs.rb +112 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit.rb +200 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit.rb +43 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_all.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/exit_program.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/find_method.rb +191 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/fix_indent.rb +19 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_cd.rb +26 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_install.rb +32 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_list.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_open.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_readme.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_search.rb +40 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gem_stats.rb +83 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/gist.rb +102 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/help.rb +164 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/hist.rb +181 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/import_set.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/install_command.rb +54 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/jump_to.rb +29 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/list_inspectors.rb +35 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/constants.rb +58 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/formatter.rb +51 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/globals.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/grep.rb +19 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/instance_vars.rb +38 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_names.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/local_vars.rb +37 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/ls_entity.rb +69 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods.rb +54 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls/self_methods.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ls.rb +113 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/nesting.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/play.rb +102 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_backtrace.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/pry_version.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/raise_up.rb +33 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reload_code.rb +62 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/reset.rb +18 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/ri.rb +65 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/save_file.rb +61 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_command.rb +75 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/shell_mode.rb +25 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_doc.rb +81 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_info.rb +216 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_input.rb +17 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/show_source.rb +53 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/stat.rb +40 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/switch_to.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/toggle_color.rb +24 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/watch_expression.rb +107 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/whereami.rb +197 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands/wtf.rb +70 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/commands.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/behavior.rb +255 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/convenience.rb +28 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/default.rb +159 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config/memoization.rb +48 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/config.rb +35 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/core_extensions.rb +142 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/editor.rb +128 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/exceptions.rb +76 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/forwardable.rb +23 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/base_helpers.rb +200 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/command_helpers.rb +157 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/documentation_helpers.rb +76 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/options_helpers.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/platform.rb +58 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/table.rb +114 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers/text.rb +115 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/helpers.rb +6 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/history.rb +161 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/hooks.rb +171 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/indent.rb +408 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_completer.rb +265 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/input_lock.rb +130 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/inspector.rb +27 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/last_exception.rb +61 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/disowned.rb +55 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/patcher.rb +122 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method/weird_method_locator.rb +198 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/method.rb +552 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/object_path.rb +83 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/output.rb +50 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pager.rb +250 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/platform.rb +91 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/plugins.rb +122 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/prompt.rb +145 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_class.rb +425 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/pry_instance.rb +699 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl.rb +261 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/repl_file_loader.rb +73 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/ring.rb +84 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/rubygem.rb +84 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/LICENSE +20 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/commands.rb +195 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop/option.rb +206 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/slop.rb +661 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/terminal.rb +91 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/evalable.rb +15 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/mockable.rb +14 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/pry_tester.rb +73 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/utility.rb +26 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable/variables.rb +46 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/testable.rb +70 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/version.rb +3 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module/candidate.rb +131 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry/wrapped_module.rb +378 -0
- data/vendor/bundle/gems/pry-0.12.2/lib/pry.rb +132 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/CHANGES +94 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/LICENSE +25 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/README.md +81 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/Rakefile +25 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/bench/_rl_adjust_point.rb +26 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline.rb +8 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/example_readline_with_completion.rb +18 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/examples/tinyirb.rb +11 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rb-readline.rb +18 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline/version.rb +3 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/rbreadline.rb +8920 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/lib/readline.rb +539 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/rb-readline.gemspec +51 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/setup.rb +1585 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/support/filesystem_completion_helper.rb +53 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_completion.rb +100 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_filename_completion_proc.rb +88 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_history.rb +29 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_rbreadline.rb +23 -0
- data/vendor/bundle/gems/rb-readline-0.5.5/test/test_readline.rb +221 -0
- data/vendor/bundle/specifications/coderay-1.1.2.gemspec +26 -0
- data/vendor/bundle/specifications/colorize-0.8.1.gemspec +38 -0
- data/vendor/bundle/specifications/method_source-0.9.2.gemspec +35 -0
- data/vendor/bundle/specifications/pry-0.12.2.gemspec +38 -0
- data/vendor/bundle/specifications/rb-readline-0.5.5.gemspec +39 -0
- metadata +363 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
class Pry
|
2
|
+
class Method
|
3
|
+
# A Disowned Method is one that's been removed from the class on which it was defined.
|
4
|
+
#
|
5
|
+
# e.g.
|
6
|
+
# class C
|
7
|
+
# def foo
|
8
|
+
# C.send(:undefine_method, :foo)
|
9
|
+
# Pry::Method.from_binding(binding)
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# In this case we assume that the "owner" is the singleton class of the receiver.
|
14
|
+
#
|
15
|
+
# This occurs mainly in Sinatra applications.
|
16
|
+
class Disowned < Method
|
17
|
+
attr_reader :receiver, :name
|
18
|
+
|
19
|
+
# Create a new Disowned method.
|
20
|
+
#
|
21
|
+
# @param [Object] receiver
|
22
|
+
# @param [String] method_name
|
23
|
+
def initialize(receiver, method_name)
|
24
|
+
@receiver, @name = receiver, method_name
|
25
|
+
@method = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
# Is the method undefined? (aka `Disowned`)
|
29
|
+
# @return [Boolean] true
|
30
|
+
def undefined?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
# Can we get the source for this method?
|
35
|
+
# @return [Boolean] false
|
36
|
+
def source?
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get the hypothesized owner of the method.
|
41
|
+
#
|
42
|
+
# @return [Object]
|
43
|
+
def owner
|
44
|
+
class << receiver; self; end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Raise a more useful error message instead of trying to forward to nil.
|
48
|
+
def method_missing(meth_name, *args, &block)
|
49
|
+
raise "Cannot call '#{meth_name}' on an undef'd method." if method(:name).respond_to?(meth_name)
|
50
|
+
|
51
|
+
Object.instance_method(:method_missing).bind(self).call(meth_name, *args, &block)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
class Pry
|
2
|
+
class Method
|
3
|
+
class Patcher
|
4
|
+
attr_accessor :method
|
5
|
+
|
6
|
+
@@source_cache = {}
|
7
|
+
|
8
|
+
def initialize(method)
|
9
|
+
@method = method
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.code_for(filename)
|
13
|
+
@@source_cache[filename]
|
14
|
+
end
|
15
|
+
|
16
|
+
# perform the patch
|
17
|
+
def patch_in_ram(source)
|
18
|
+
if method.alias?
|
19
|
+
with_method_transaction do
|
20
|
+
redefine source
|
21
|
+
end
|
22
|
+
else
|
23
|
+
redefine source
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def redefine(source)
|
30
|
+
@@source_cache[cache_key] = source
|
31
|
+
TOPLEVEL_BINDING.eval wrap(source), cache_key
|
32
|
+
end
|
33
|
+
|
34
|
+
def cache_key
|
35
|
+
"pry-redefined(0x#{method.owner.object_id.to_s(16)}##{method.name})"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Run some code ensuring that at the end target#meth_name will not have changed.
|
39
|
+
#
|
40
|
+
# When we're redefining aliased methods we will overwrite the method at the
|
41
|
+
# unaliased name (so that super continues to work). By wrapping that code in a
|
42
|
+
# transation we make that not happen, which means that alias_method_chains, etc.
|
43
|
+
# continue to work.
|
44
|
+
#
|
45
|
+
def with_method_transaction
|
46
|
+
temp_name = "__pry_#{method.original_name}__"
|
47
|
+
method = self.method
|
48
|
+
method.owner.class_eval do
|
49
|
+
alias_method temp_name, method.original_name
|
50
|
+
yield
|
51
|
+
alias_method method.name, method.original_name
|
52
|
+
alias_method method.original_name, temp_name
|
53
|
+
end
|
54
|
+
|
55
|
+
ensure
|
56
|
+
method.send(:remove_method, temp_name) rescue nil
|
57
|
+
end
|
58
|
+
|
59
|
+
# Update the definition line so that it can be eval'd directly on the Method's
|
60
|
+
# owner instead of from the original context.
|
61
|
+
#
|
62
|
+
# In particular this takes `def self.foo` and turns it into `def foo` so that we
|
63
|
+
# don't end up creating the method on the singleton class of the singleton class
|
64
|
+
# by accident.
|
65
|
+
#
|
66
|
+
# This is necessarily done by String manipulation because we can't find out what
|
67
|
+
# syntax is needed for the argument list by ruby-level introspection.
|
68
|
+
#
|
69
|
+
# @param [String] line The original definition line. e.g. def self.foo(bar, baz=1)
|
70
|
+
# @return [String] The new definition line. e.g. def foo(bar, baz=1)
|
71
|
+
def definition_for_owner(line)
|
72
|
+
if line =~ /\Adef (?:.*?\.)?#{Regexp.escape(method.original_name)}(?=[\(\s;]|$)/
|
73
|
+
"def #{method.original_name}#{$'}"
|
74
|
+
else
|
75
|
+
raise CommandError, "Could not find original `def #{method.original_name}` line to patch."
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Apply wrap_for_owner and wrap_for_nesting successively to `source`
|
80
|
+
# @param [String] source
|
81
|
+
# @return [String] The wrapped source.
|
82
|
+
def wrap(source)
|
83
|
+
wrap_for_nesting(wrap_for_owner(source))
|
84
|
+
end
|
85
|
+
|
86
|
+
# Update the source code so that when it has the right owner when eval'd.
|
87
|
+
#
|
88
|
+
# This (combined with definition_for_owner) is backup for the case that
|
89
|
+
# wrap_for_nesting fails, to ensure that the method will stil be defined in
|
90
|
+
# the correct place.
|
91
|
+
#
|
92
|
+
# @param [String] source The source to wrap
|
93
|
+
# @return [String]
|
94
|
+
def wrap_for_owner(source)
|
95
|
+
Pry.current[:pry_owner] = method.owner
|
96
|
+
owner_source = definition_for_owner(source)
|
97
|
+
visibility_fix = "#{method.visibility} #{method.name.to_sym.inspect}"
|
98
|
+
"Pry.current[:pry_owner].class_eval do; #{owner_source}\n#{visibility_fix}\nend"
|
99
|
+
end
|
100
|
+
|
101
|
+
# Update the new source code to have the correct Module.nesting.
|
102
|
+
#
|
103
|
+
# This method uses syntactic analysis of the original source file to determine
|
104
|
+
# the new nesting, so that we can tell the difference between:
|
105
|
+
#
|
106
|
+
# class A; def self.b; end; end
|
107
|
+
# class << A; def b; end; end
|
108
|
+
#
|
109
|
+
# The resulting code should be evaluated in the TOPLEVEL_BINDING.
|
110
|
+
#
|
111
|
+
# @param [String] source The source to wrap.
|
112
|
+
# @return [String]
|
113
|
+
def wrap_for_nesting(source)
|
114
|
+
nesting = Pry::Code.from_file(method.source_file).nesting_at(method.source_line)
|
115
|
+
|
116
|
+
(nesting + [source] + nesting.map { "end" } + [""]).join(";")
|
117
|
+
rescue Pry::Indent::UnparseableNestingError
|
118
|
+
source
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
class Pry
|
2
|
+
class Method
|
3
|
+
# This class is responsible for locating the *real* `Pry::Method`
|
4
|
+
# object captured by a binding.
|
5
|
+
#
|
6
|
+
# Given a `Binding` from inside a method and a 'seed' Pry::Method object,
|
7
|
+
# there are primarily two situations where the seed method doesn't match
|
8
|
+
# the Binding:
|
9
|
+
# 1. The Pry::Method is from a subclass 2. The Pry::Method represents a method of the same name
|
10
|
+
# while the original was renamed to something else. For 1. we
|
11
|
+
# search vertically up the inheritance chain,
|
12
|
+
# and for 2. we search laterally along the object's method table.
|
13
|
+
#
|
14
|
+
# When we locate the method that matches the Binding we wrap it in
|
15
|
+
# Pry::Method and return it, or return nil if we fail.
|
16
|
+
class WeirdMethodLocator
|
17
|
+
class << self
|
18
|
+
# Whether the given method object matches the associated binding.
|
19
|
+
# If the method object does not match the binding, then it's
|
20
|
+
# most likely not the method captured by the binding, and we
|
21
|
+
# must commence a search.
|
22
|
+
#
|
23
|
+
# @param [Pry::Method] method
|
24
|
+
# @param [Binding] b
|
25
|
+
# @return [Boolean]
|
26
|
+
def normal_method?(method, b)
|
27
|
+
if method and method.source_file and method.source_range
|
28
|
+
binding_file, binding_line = b.eval('__FILE__'), b.eval('__LINE__')
|
29
|
+
File.expand_path(method.source_file) == File.expand_path(binding_file) and
|
30
|
+
method.source_range.include?(binding_line)
|
31
|
+
end
|
32
|
+
rescue
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def weird_method?(method, b)
|
37
|
+
not normal_method?(method, b)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_accessor :method
|
42
|
+
attr_accessor :target
|
43
|
+
|
44
|
+
# @param [Pry::Method] method The seed method.
|
45
|
+
# @param [Binding] target The Binding that captures the method
|
46
|
+
# we want to locate.
|
47
|
+
def initialize(method, target)
|
48
|
+
@method, @target = method, target
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Pry::Method, nil] The Pry::Method that matches the
|
52
|
+
# given binding.
|
53
|
+
def get_method
|
54
|
+
find_method_in_superclass || find_renamed_method
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean] Whether the Pry::Method is unrecoverable
|
58
|
+
# This usually happens when the method captured by the Binding
|
59
|
+
# has been subsequently deleted.
|
60
|
+
def lost_method?
|
61
|
+
!!(get_method.nil? && renamed_method_source_location)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def skip_superclass_search?
|
67
|
+
target_mod = @target.eval('self').class
|
68
|
+
target_mod.ancestors.take_while { |mod| mod != target_mod }.any?
|
69
|
+
end
|
70
|
+
|
71
|
+
def normal_method?(method)
|
72
|
+
self.class.normal_method?(method, target)
|
73
|
+
end
|
74
|
+
|
75
|
+
def target_self
|
76
|
+
target.eval('self')
|
77
|
+
end
|
78
|
+
|
79
|
+
def target_file
|
80
|
+
pry_file? ? target.eval('__FILE__') : File.expand_path(target.eval('__FILE__'))
|
81
|
+
end
|
82
|
+
|
83
|
+
def target_line
|
84
|
+
target.eval('__LINE__')
|
85
|
+
end
|
86
|
+
|
87
|
+
def pry_file?
|
88
|
+
Pry.eval_path == target.eval('__FILE__')
|
89
|
+
end
|
90
|
+
|
91
|
+
# it's possible in some cases that the method we find by this approach is a sub-method of
|
92
|
+
# the one we're currently in, consider:
|
93
|
+
#
|
94
|
+
# class A; def b; binding.pry; end; end
|
95
|
+
# class B < A; def b; super; end; end
|
96
|
+
#
|
97
|
+
# Given that we can normally find the source_range of methods, and that we know which
|
98
|
+
# __FILE__ and __LINE__ the binding is at, we can hope to disambiguate these cases.
|
99
|
+
#
|
100
|
+
# This obviously won't work if the source is unavaiable for some reason, or if both
|
101
|
+
# methods have the same __FILE__ and __LINE__.
|
102
|
+
#
|
103
|
+
# @return [Pry::Method, nil] The Pry::Method representing the
|
104
|
+
# superclass method.
|
105
|
+
def find_method_in_superclass
|
106
|
+
guess = method
|
107
|
+
if skip_superclass_search?
|
108
|
+
return guess
|
109
|
+
end
|
110
|
+
|
111
|
+
while guess
|
112
|
+
# needs rescue if this is a Disowned method or a C method or something...
|
113
|
+
# TODO: Fix up the exception handling so we don't need a bare rescue
|
114
|
+
if normal_method?(guess)
|
115
|
+
return guess
|
116
|
+
elsif guess != guess.super
|
117
|
+
guess = guess.super
|
118
|
+
else
|
119
|
+
break
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Uhoh... none of the methods in the chain had the right `__FILE__` and
|
124
|
+
# `__LINE__` due to unknown circumstances.
|
125
|
+
# TODO: we should warn the user when this happens.
|
126
|
+
nil
|
127
|
+
end
|
128
|
+
|
129
|
+
# This is the case where the name of a method has changed
|
130
|
+
# (via alias_method) so we locate the Method object for the
|
131
|
+
# renamed method.
|
132
|
+
#
|
133
|
+
# @return [Pry::Method, nil] The Pry::Method representing the
|
134
|
+
# renamed method
|
135
|
+
def find_renamed_method
|
136
|
+
return if !valid_file?(target_file)
|
137
|
+
|
138
|
+
alias_name = all_methods_for(target_self).find do |v|
|
139
|
+
expanded_source_location(target_self.method(v).source_location) == renamed_method_source_location
|
140
|
+
end
|
141
|
+
|
142
|
+
alias_name && Pry::Method(target_self.method(alias_name))
|
143
|
+
end
|
144
|
+
|
145
|
+
def expanded_source_location(sl)
|
146
|
+
return if !sl
|
147
|
+
|
148
|
+
if pry_file?
|
149
|
+
sl
|
150
|
+
else
|
151
|
+
[File.expand_path(sl.first), sl.last]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# Use static analysis to locate the start of the method definition.
|
156
|
+
# We have the `__FILE__` and `__LINE__` from the binding and the
|
157
|
+
# original name of the method so we search up until we find a
|
158
|
+
# def/define_method, etc defining a method of the appropriate name.
|
159
|
+
#
|
160
|
+
# @return [Array<String, Fixnum>] The `source_location` of the
|
161
|
+
# renamed method
|
162
|
+
def renamed_method_source_location
|
163
|
+
return @original_method_source_location if defined?(@original_method_source_location)
|
164
|
+
|
165
|
+
source_index = lines_for_file(target_file)[0..(target_line - 1)].rindex do |v|
|
166
|
+
Pry::Method.method_definition?(method.name, v)
|
167
|
+
end
|
168
|
+
|
169
|
+
@original_method_source_location = source_index &&
|
170
|
+
[target_file, index_to_line_number(source_index)]
|
171
|
+
end
|
172
|
+
|
173
|
+
def index_to_line_number(index)
|
174
|
+
# Pry.line_buffer is 0-indexed
|
175
|
+
pry_file? ? index : index + 1
|
176
|
+
end
|
177
|
+
|
178
|
+
def valid_file?(file)
|
179
|
+
(File.exist?(file) && !File.directory?(file)) || Pry.eval_path == file
|
180
|
+
end
|
181
|
+
|
182
|
+
def lines_for_file(file)
|
183
|
+
@lines_for_file ||= {}
|
184
|
+
@lines_for_file[file] ||= if Pry.eval_path == file
|
185
|
+
Pry.line_buffer
|
186
|
+
else
|
187
|
+
File.readlines(file)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def all_methods_for(obj)
|
192
|
+
obj.public_methods(false) +
|
193
|
+
obj.private_methods(false) +
|
194
|
+
obj.protected_methods(false)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,552 @@
|
|
1
|
+
require 'pry/helpers/documentation_helpers'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class << self
|
5
|
+
# If the given object is a `Pry::Method`, return it unaltered. If it's
|
6
|
+
# anything else, return it wrapped in a `Pry::Method` instance.
|
7
|
+
def Method(obj)
|
8
|
+
if obj.is_a? Pry::Method
|
9
|
+
obj
|
10
|
+
else
|
11
|
+
Pry::Method.new(obj)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# This class wraps the normal `Method` and `UnboundMethod` classes
|
17
|
+
# to provide extra functionality useful to Pry.
|
18
|
+
class Method
|
19
|
+
require 'pry/method/weird_method_locator'
|
20
|
+
require 'pry/method/disowned'
|
21
|
+
require 'pry/method/patcher'
|
22
|
+
|
23
|
+
extend Helpers::BaseHelpers
|
24
|
+
include Helpers::BaseHelpers
|
25
|
+
include Helpers::DocumentationHelpers
|
26
|
+
include CodeObject::Helpers
|
27
|
+
|
28
|
+
class << self
|
29
|
+
# Given a string representing a method name and optionally a binding to
|
30
|
+
# search in, find and return the requested method wrapped in a `Pry::Method`
|
31
|
+
# instance.
|
32
|
+
#
|
33
|
+
# @param [String] name The name of the method to retrieve.
|
34
|
+
# @param [Binding] target The context in which to search for the method.
|
35
|
+
# @param [Hash] options
|
36
|
+
# @option options [Boolean] :instance Look for an instance method if `name` doesn't
|
37
|
+
# contain any context.
|
38
|
+
# @option options [Boolean] :methods Look for a bound/singleton method if `name` doesn't
|
39
|
+
# contain any context.
|
40
|
+
# @return [Pry::Method, nil] A `Pry::Method` instance containing the requested
|
41
|
+
# method, or `nil` if name is `nil` or no method could be located matching the parameters.
|
42
|
+
def from_str(name, target = TOPLEVEL_BINDING, options = {})
|
43
|
+
if name.nil?
|
44
|
+
nil
|
45
|
+
elsif name.to_s =~ /(.+)\#(\S+)\Z/
|
46
|
+
context, meth_name = $1, $2
|
47
|
+
from_module(target.eval(context), meth_name, target)
|
48
|
+
elsif name.to_s =~ /(.+)(\[\])\Z/
|
49
|
+
context, meth_name = $1, $2
|
50
|
+
from_obj(target.eval(context), meth_name, target)
|
51
|
+
elsif name.to_s =~ /(.+)(\.|::)(\S+)\Z/
|
52
|
+
context, meth_name = $1, $3
|
53
|
+
from_obj(target.eval(context), meth_name, target)
|
54
|
+
elsif options[:instance]
|
55
|
+
from_module(target.eval("self"), name, target)
|
56
|
+
elsif options[:methods]
|
57
|
+
from_obj(target.eval("self"), name, target)
|
58
|
+
else
|
59
|
+
from_str(name, target, instance: true) or
|
60
|
+
from_str(name, target, methods: true)
|
61
|
+
end
|
62
|
+
|
63
|
+
rescue Pry::RescuableException
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
# Given a `Binding`, try to extract the `::Method` it originated from and
|
68
|
+
# use it to instantiate a `Pry::Method`. Return `nil` if this isn't
|
69
|
+
# possible.
|
70
|
+
#
|
71
|
+
# @param [Binding] b
|
72
|
+
# @return [Pry::Method, nil]
|
73
|
+
#
|
74
|
+
def from_binding(b)
|
75
|
+
meth_name = b.eval('::Kernel.__method__')
|
76
|
+
if [:__script__, nil].include?(meth_name)
|
77
|
+
nil
|
78
|
+
else
|
79
|
+
method = begin
|
80
|
+
if Object === b.eval('self')
|
81
|
+
new(Kernel.instance_method(:method).bind(b.eval("self")).call(meth_name))
|
82
|
+
else
|
83
|
+
new(b.eval('class << self; self; end.instance_method(::Kernel.__method__).bind(self)'))
|
84
|
+
end
|
85
|
+
rescue NameError, NoMethodError
|
86
|
+
Disowned.new(b.eval('self'), meth_name.to_s)
|
87
|
+
end
|
88
|
+
|
89
|
+
if WeirdMethodLocator.weird_method?(method, b)
|
90
|
+
WeirdMethodLocator.new(method, b).get_method || method
|
91
|
+
else
|
92
|
+
method
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# In order to support 2.0 Refinements we need to look up methods
|
98
|
+
# inside the relevant Binding.
|
99
|
+
# @param [Object] obj The owner/receiver of the method.
|
100
|
+
# @param [Symbol] method_name The name of the method.
|
101
|
+
# @param [Symbol] method_type The type of method: :method or :instance_method
|
102
|
+
# @param [Binding] target The binding where the method is looked up.
|
103
|
+
# @return [Method, UnboundMethod] The 'refined' method object.
|
104
|
+
def lookup_method_via_binding(obj, method_name, method_type, target = TOPLEVEL_BINDING)
|
105
|
+
Pry.current[:obj] = obj
|
106
|
+
Pry.current[:name] = method_name
|
107
|
+
receiver = obj.is_a?(Module) ? "Module" : "Kernel"
|
108
|
+
target.eval("::#{receiver}.instance_method(:#{method_type}).bind(Pry.current[:obj]).call(Pry.current[:name])")
|
109
|
+
ensure
|
110
|
+
Pry.current[:obj] = Pry.current[:name] = nil
|
111
|
+
end
|
112
|
+
|
113
|
+
# Given a `Class` or `Module` and the name of a method, try to
|
114
|
+
# instantiate a `Pry::Method` containing the instance method of
|
115
|
+
# that name. Return `nil` if no such method exists.
|
116
|
+
#
|
117
|
+
# @param [Class, Module] klass
|
118
|
+
# @param [String] name
|
119
|
+
# @param [Binding] target The binding where the method is looked up.
|
120
|
+
# @return [Pry::Method, nil]
|
121
|
+
def from_class(klass, name, target = TOPLEVEL_BINDING)
|
122
|
+
new(lookup_method_via_binding(klass, name, :instance_method, target)) rescue nil
|
123
|
+
end
|
124
|
+
alias from_module from_class
|
125
|
+
|
126
|
+
# Given an object and the name of a method, try to instantiate
|
127
|
+
# a `Pry::Method` containing the method of that name bound to
|
128
|
+
# that object. Return `nil` if no such method exists.
|
129
|
+
#
|
130
|
+
# @param [Object] obj
|
131
|
+
# @param [String] name
|
132
|
+
# @param [Binding] target The binding where the method is looked up.
|
133
|
+
# @return [Pry::Method, nil]
|
134
|
+
def from_obj(obj, name, target = TOPLEVEL_BINDING)
|
135
|
+
new(lookup_method_via_binding(obj, name, :method, target)) rescue nil
|
136
|
+
end
|
137
|
+
|
138
|
+
# Get all of the instance methods of a `Class` or `Module`
|
139
|
+
# @param [Class,Module] klass
|
140
|
+
# @param [Boolean] include_super Whether to include methods from ancestors.
|
141
|
+
# @return [Array[Pry::Method]]
|
142
|
+
def all_from_class(klass, include_super = true)
|
143
|
+
%w(public protected private).flat_map do |visibility|
|
144
|
+
safe_send(klass, :"#{visibility}_instance_methods", include_super).map do |method_name|
|
145
|
+
new(safe_send(klass, :instance_method, method_name), visibility: visibility.to_sym)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# Get all of the methods on an `Object`
|
152
|
+
#
|
153
|
+
# @param [Object] obj
|
154
|
+
#
|
155
|
+
# @param [Boolean] include_super
|
156
|
+
# indicates whether or not to include methods from ancestors.
|
157
|
+
#
|
158
|
+
# @return [Array[Pry::Method]]
|
159
|
+
#
|
160
|
+
def all_from_obj(obj, include_super = true)
|
161
|
+
all_from_class(singleton_class_of(obj), include_super)
|
162
|
+
end
|
163
|
+
|
164
|
+
#
|
165
|
+
# @deprecated
|
166
|
+
# please use {all_from_obj} instead.
|
167
|
+
# the `method_type` argument is ignored.
|
168
|
+
#
|
169
|
+
def all_from_common(obj, _method_type = nil, include_super = true)
|
170
|
+
all_from_obj(obj, include_super)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Get every `Class` and `Module`, in order, that will be checked when looking
|
174
|
+
# for an instance method to call on this object.
|
175
|
+
# @param [Object] obj
|
176
|
+
# @return [Array[Class, Module]]
|
177
|
+
def resolution_order(obj)
|
178
|
+
if Class === obj
|
179
|
+
singleton_class_resolution_order(obj) + instance_resolution_order(Class)
|
180
|
+
else
|
181
|
+
klass = singleton_class_of(obj) rescue obj.class
|
182
|
+
instance_resolution_order(klass)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Get every `Class` and `Module`, in order, that will be checked when looking
|
187
|
+
# for methods on instances of the given `Class` or `Module`.
|
188
|
+
# This does not treat singleton classes of classes specially.
|
189
|
+
# @param [Class, Module] klass
|
190
|
+
# @return [Array[Class, Module]]
|
191
|
+
def instance_resolution_order(klass)
|
192
|
+
# include klass in case it is a singleton class,
|
193
|
+
([klass] + Pry::Method.safe_send(klass, :ancestors)).uniq
|
194
|
+
end
|
195
|
+
|
196
|
+
def method_definition?(name, definition_line)
|
197
|
+
singleton_method_definition?(name, definition_line) ||
|
198
|
+
instance_method_definition?(name, definition_line)
|
199
|
+
end
|
200
|
+
|
201
|
+
def singleton_method_definition?(name, definition_line)
|
202
|
+
/^define_singleton_method\(?\s*[:\"\']#{Regexp.escape(name)}|^def\s*self\.#{Regexp.escape(name)}/ =~ definition_line.strip
|
203
|
+
end
|
204
|
+
|
205
|
+
def instance_method_definition?(name, definition_line)
|
206
|
+
/^define_method\(?\s*[:\"\']#{Regexp.escape(name)}|^def\s*#{Regexp.escape(name)}/ =~ definition_line.strip
|
207
|
+
end
|
208
|
+
|
209
|
+
# Get the singleton classes of superclasses that could define methods on
|
210
|
+
# the given class object, and any modules they include.
|
211
|
+
# If a module is included at multiple points in the ancestry, only
|
212
|
+
# the lowest copy will be returned.
|
213
|
+
def singleton_class_resolution_order(klass)
|
214
|
+
ancestors = Pry::Method.safe_send(klass, :ancestors)
|
215
|
+
resolution_order = ancestors.grep(Class).flat_map do |anc|
|
216
|
+
[singleton_class_of(anc), *singleton_class_of(anc).included_modules]
|
217
|
+
end
|
218
|
+
|
219
|
+
resolution_order.reverse.uniq.reverse - Class.included_modules
|
220
|
+
end
|
221
|
+
|
222
|
+
def singleton_class_of(obj)
|
223
|
+
begin
|
224
|
+
class << obj; self; end
|
225
|
+
rescue TypeError # can't define singleton. Fixnum, Symbol, Float, ...
|
226
|
+
obj.class
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
# A new instance of `Pry::Method` wrapping the given `::Method`, `UnboundMethod`, or `Proc`.
|
232
|
+
#
|
233
|
+
# @param [::Method, UnboundMethod, Proc] method
|
234
|
+
# @param [Hash] known_info Can be used to pre-cache expensive to compute stuff.
|
235
|
+
# @return [Pry::Method]
|
236
|
+
def initialize(method, known_info = {})
|
237
|
+
@method = method
|
238
|
+
@visibility = known_info[:visibility]
|
239
|
+
end
|
240
|
+
|
241
|
+
# Get the name of the method as a String, regardless of the underlying Method#name type.
|
242
|
+
# @return [String]
|
243
|
+
def name
|
244
|
+
@method.name.to_s
|
245
|
+
end
|
246
|
+
|
247
|
+
# Get the owner of the method as a Pry::Module
|
248
|
+
# @return [Pry::Module]
|
249
|
+
def wrapped_owner
|
250
|
+
@wrapped_owner ||= Pry::WrappedModule.new(owner)
|
251
|
+
end
|
252
|
+
|
253
|
+
# Get underlying object wrapped by this Pry::Method instance
|
254
|
+
# @return [Method, UnboundMethod, Proc]
|
255
|
+
def wrapped
|
256
|
+
@method
|
257
|
+
end
|
258
|
+
|
259
|
+
# Is the method undefined? (aka `Disowned`)
|
260
|
+
# @return [Boolean] false
|
261
|
+
def undefined?
|
262
|
+
false
|
263
|
+
end
|
264
|
+
|
265
|
+
# Get the name of the method including the class on which it was defined.
|
266
|
+
# @example
|
267
|
+
# method(:puts).method_name
|
268
|
+
# => "Kernel.puts"
|
269
|
+
# @return [String]
|
270
|
+
def name_with_owner
|
271
|
+
"#{wrapped_owner.method_prefix}#{name}"
|
272
|
+
end
|
273
|
+
|
274
|
+
# @return [String, nil] The source code of the method, or `nil` if it's unavailable.
|
275
|
+
def source
|
276
|
+
@source ||= case source_type
|
277
|
+
when :c
|
278
|
+
c_source
|
279
|
+
when :ruby
|
280
|
+
ruby_source
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
# Update the live copy of the method's source.
|
285
|
+
def redefine(source)
|
286
|
+
Patcher.new(self).patch_in_ram source
|
287
|
+
Pry::Method(owner.instance_method(name))
|
288
|
+
end
|
289
|
+
|
290
|
+
# Can we get the source code for this method?
|
291
|
+
# @return [Boolean]
|
292
|
+
def source?
|
293
|
+
!!source
|
294
|
+
rescue MethodSource::SourceNotFoundError
|
295
|
+
false
|
296
|
+
end
|
297
|
+
|
298
|
+
# @return [String, nil] The documentation for the method, or `nil` if it's
|
299
|
+
# unavailable.
|
300
|
+
def doc
|
301
|
+
@doc ||=
|
302
|
+
case source_type
|
303
|
+
when :c
|
304
|
+
info = pry_doc_info
|
305
|
+
info.docstring if info
|
306
|
+
when :ruby
|
307
|
+
get_comment_content(comment)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
# @return [Symbol] The source type of the method. The options are
|
312
|
+
# `:ruby` for Ruby methods or `:c` for methods written in C.
|
313
|
+
def source_type
|
314
|
+
source_location.nil? ? :c : :ruby
|
315
|
+
end
|
316
|
+
|
317
|
+
# @return [String, nil] The name of the file the method is defined in, or
|
318
|
+
# `nil` if the filename is unavailable.
|
319
|
+
def source_file
|
320
|
+
if source_location.nil?
|
321
|
+
if source_type == :c
|
322
|
+
info = pry_doc_info
|
323
|
+
info.file if info
|
324
|
+
end
|
325
|
+
else
|
326
|
+
source_location.first
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
# @return [Fixnum, nil] The line of code in `source_file` which begins
|
331
|
+
# the method's definition, or `nil` if that information is unavailable.
|
332
|
+
def source_line
|
333
|
+
source_location.nil? ? nil : source_location.last
|
334
|
+
end
|
335
|
+
|
336
|
+
# @return [Range, nil] The range of lines in `source_file` which contain
|
337
|
+
# the method's definition, or `nil` if that information is unavailable.
|
338
|
+
def source_range
|
339
|
+
source_location.nil? ? nil : (source_line)..(source_line + source.lines.count - 1)
|
340
|
+
end
|
341
|
+
|
342
|
+
# @return [Symbol] The visibility of the method. May be `:public`,
|
343
|
+
# `:protected`, or `:private`.
|
344
|
+
def visibility
|
345
|
+
@visibility ||= if owner.public_instance_methods.any? { |m| m.to_s == name }
|
346
|
+
:public
|
347
|
+
elsif owner.protected_instance_methods.any? { |m| m.to_s == name }
|
348
|
+
:protected
|
349
|
+
elsif owner.private_instance_methods.any? { |m| m.to_s == name }
|
350
|
+
:private
|
351
|
+
else
|
352
|
+
:none
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
# @return [String] A representation of the method's signature, including its
|
357
|
+
# name and parameters. Optional and "rest" parameters are marked with `*`
|
358
|
+
# and block parameters with `&`. Keyword arguments are shown with `:`
|
359
|
+
# If the parameter names are unavailable, they're given numbered names instead.
|
360
|
+
# Paraphrased from `awesome_print` gem.
|
361
|
+
def signature
|
362
|
+
if respond_to?(:parameters)
|
363
|
+
args = parameters.inject([]) do |args_array, (arg_type, name)|
|
364
|
+
name ||= (arg_type == :block ? 'block' : "arg#{args_array.size + 1}")
|
365
|
+
args_array.push(
|
366
|
+
case arg_type
|
367
|
+
when :req then name.to_s
|
368
|
+
when :opt then "#{name}=?"
|
369
|
+
when :rest then "*#{name}"
|
370
|
+
when :block then "&#{name}"
|
371
|
+
when :key then "#{name}:?"
|
372
|
+
when :keyreq then "#{name}:"
|
373
|
+
else '?'
|
374
|
+
end
|
375
|
+
)
|
376
|
+
end
|
377
|
+
else
|
378
|
+
args = (1..arity.abs).map { |i| "arg#{i}" }
|
379
|
+
args[-1] = "*#{args[-1]}" if arity < 0
|
380
|
+
end
|
381
|
+
|
382
|
+
"#{name}(#{args.join(', ')})"
|
383
|
+
end
|
384
|
+
|
385
|
+
# @return [Pry::Method, nil] The wrapped method that is called when you
|
386
|
+
# use "super" in the body of this method.
|
387
|
+
def super(times = 1)
|
388
|
+
if UnboundMethod === @method
|
389
|
+
sup = super_using_ancestors(Pry::Method.instance_resolution_order(owner), times)
|
390
|
+
else
|
391
|
+
sup = super_using_ancestors(Pry::Method.resolution_order(receiver), times)
|
392
|
+
sup &&= sup.bind(receiver)
|
393
|
+
end
|
394
|
+
Pry::Method.new(sup) if sup
|
395
|
+
end
|
396
|
+
|
397
|
+
# @return [String, nil] The original name the method was defined under,
|
398
|
+
# before any aliasing, or `nil` if it can't be determined.
|
399
|
+
def original_name
|
400
|
+
return nil if source_type != :ruby
|
401
|
+
|
402
|
+
method_name_from_first_line(source.lines.first)
|
403
|
+
end
|
404
|
+
|
405
|
+
# @return [Boolean] Was the method defined outside a source file?
|
406
|
+
def dynamically_defined?
|
407
|
+
!!(source_file and source_file =~ /(\(.*\))|<.*>/)
|
408
|
+
end
|
409
|
+
|
410
|
+
# @return [Boolean] Whether the method is unbound.
|
411
|
+
def unbound_method?
|
412
|
+
is_a?(::UnboundMethod)
|
413
|
+
end
|
414
|
+
|
415
|
+
# @return [Boolean] Whether the method is bound.
|
416
|
+
def bound_method?
|
417
|
+
is_a?(::Method)
|
418
|
+
end
|
419
|
+
|
420
|
+
# @return [Boolean] Whether the method is a singleton method.
|
421
|
+
def singleton_method?
|
422
|
+
wrapped_owner.singleton_class?
|
423
|
+
end
|
424
|
+
|
425
|
+
# @return [Boolean] Was the method defined within the Pry REPL?
|
426
|
+
def pry_method?
|
427
|
+
source_file == Pry.eval_path
|
428
|
+
end
|
429
|
+
|
430
|
+
# @return [Array<String>] All known aliases for the method.
|
431
|
+
def aliases
|
432
|
+
owner = @method.owner
|
433
|
+
# Avoid using `to_sym` on {Method#name}, which returns a `String`, because
|
434
|
+
# it won't be garbage collected.
|
435
|
+
name = @method.name
|
436
|
+
|
437
|
+
all_methods_to_compare = owner.instance_methods | owner.private_instance_methods
|
438
|
+
alias_list = all_methods_to_compare.combination(2).select do |pair|
|
439
|
+
pair.include?(name) &&
|
440
|
+
owner.instance_method(pair.first) == owner.instance_method(pair.last)
|
441
|
+
end.flatten
|
442
|
+
alias_list.delete(name)
|
443
|
+
|
444
|
+
alias_list.map(&:to_s)
|
445
|
+
end
|
446
|
+
|
447
|
+
# @return [Boolean] Is the method definitely an alias?
|
448
|
+
def alias?
|
449
|
+
name != original_name
|
450
|
+
end
|
451
|
+
|
452
|
+
# @return [Boolean]
|
453
|
+
def ==(obj)
|
454
|
+
if obj.is_a? Pry::Method
|
455
|
+
obj == @method
|
456
|
+
else
|
457
|
+
@method == obj
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
# @param [Class] klass
|
462
|
+
# @return [Boolean]
|
463
|
+
def is_a?(klass)
|
464
|
+
klass == Pry::Method or @method.is_a?(klass)
|
465
|
+
end
|
466
|
+
alias kind_of? is_a?
|
467
|
+
|
468
|
+
# @param [String, Symbol] method_name
|
469
|
+
# @return [Boolean]
|
470
|
+
def respond_to?(method_name, include_all = false)
|
471
|
+
super or @method.respond_to?(method_name, include_all)
|
472
|
+
end
|
473
|
+
|
474
|
+
# Delegate any unknown calls to the wrapped method.
|
475
|
+
def method_missing(method_name, *args, &block)
|
476
|
+
@method.send(method_name, *args, &block)
|
477
|
+
end
|
478
|
+
|
479
|
+
def comment
|
480
|
+
Pry::Code.from_file(source_file).comment_describing(source_line)
|
481
|
+
end
|
482
|
+
|
483
|
+
private
|
484
|
+
|
485
|
+
# @return [YARD::CodeObjects::MethodObject]
|
486
|
+
# @raise [CommandError] when the method can't be found or `pry-doc` isn't installed.
|
487
|
+
def pry_doc_info
|
488
|
+
if Pry.config.has_pry_doc
|
489
|
+
Pry::MethodInfo.info_for(@method) or raise CommandError, "Cannot locate this method: #{name}. (source_location returns nil)"
|
490
|
+
else
|
491
|
+
fail_msg = "Cannot locate this method: #{name}."
|
492
|
+
if Helpers::Platform.mri?
|
493
|
+
fail_msg += " Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.\n"
|
494
|
+
end
|
495
|
+
raise CommandError, fail_msg
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
# @param [Class, Module] ancestors The ancestors to investigate
|
500
|
+
# @return [Method] The unwrapped super-method
|
501
|
+
def super_using_ancestors(ancestors, times = 1)
|
502
|
+
next_owner = self.owner
|
503
|
+
times.times do
|
504
|
+
i = ancestors.index(next_owner) + 1
|
505
|
+
while ancestors[i] && !(ancestors[i].method_defined?(name) || ancestors[i].private_method_defined?(name))
|
506
|
+
i += 1
|
507
|
+
end
|
508
|
+
next_owner = ancestors[i] or return nil
|
509
|
+
end
|
510
|
+
|
511
|
+
safe_send(next_owner, :instance_method, name) rescue nil
|
512
|
+
end
|
513
|
+
|
514
|
+
# @param [String] first_ln The first line of a method definition.
|
515
|
+
# @return [String, nil]
|
516
|
+
def method_name_from_first_line(first_ln)
|
517
|
+
return nil if first_ln.strip !~ /^def /
|
518
|
+
|
519
|
+
tokens = CodeRay.scan(first_ln, :ruby)
|
520
|
+
tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens)
|
521
|
+
tokens.each_cons(2) do |t1, t2|
|
522
|
+
if t2.last == :method || t2.last == :ident && t1 == [".", :operator]
|
523
|
+
return t2.first
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
nil
|
528
|
+
end
|
529
|
+
|
530
|
+
def c_source
|
531
|
+
info = pry_doc_info
|
532
|
+
if info and info.source
|
533
|
+
strip_comments_from_c_code(info.source)
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
def ruby_source
|
538
|
+
# Clone of `MethodSource.source_helper` that knows to use our
|
539
|
+
# hacked version of `source_location` for our input buffer for methods
|
540
|
+
# defined in `(pry)`.
|
541
|
+
file, line = *source_location
|
542
|
+
raise SourceNotFoundError, "Could not locate source for #{name_with_owner}!" unless file
|
543
|
+
|
544
|
+
begin
|
545
|
+
code = Pry::Code.from_file(file).expression_at(line)
|
546
|
+
rescue SyntaxError => e
|
547
|
+
raise MethodSource::SourceNotFoundError.new(e.message)
|
548
|
+
end
|
549
|
+
strip_leading_whitespace(code)
|
550
|
+
end
|
551
|
+
end
|
552
|
+
end
|