pry 0.10.pre.1-i386-mingw32 → 0.10.0.pre3-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +41 -35
  5. data/lib/pry.rb +82 -139
  6. data/lib/pry/cli.rb +77 -30
  7. data/lib/pry/code.rb +122 -183
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +71 -0
  10. data/lib/pry/code/loc.rb +92 -0
  11. data/lib/pry/code_object.rb +172 -0
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +184 -28
  14. data/lib/pry/command_set.rb +113 -59
  15. data/lib/pry/commands.rb +4 -27
  16. data/lib/pry/commands/amend_line.rb +99 -0
  17. data/lib/pry/commands/bang.rb +20 -0
  18. data/lib/pry/commands/bang_pry.rb +17 -0
  19. data/lib/pry/commands/cat.rb +62 -0
  20. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  21. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  22. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  23. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  24. data/lib/pry/commands/cd.rb +41 -0
  25. data/lib/pry/commands/change_inspector.rb +27 -0
  26. data/lib/pry/commands/change_prompt.rb +26 -0
  27. data/lib/pry/commands/code_collector.rb +165 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/disabled_commands.rb +2 -0
  30. data/lib/pry/commands/easter_eggs.rb +112 -0
  31. data/lib/pry/commands/edit.rb +195 -0
  32. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +23 -0
  37. data/lib/pry/commands/find_method.rb +193 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +32 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +101 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +180 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +53 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/list_inspectors.rb +35 -0
  50. data/lib/pry/commands/list_prompts.rb +35 -0
  51. data/lib/pry/commands/ls.rb +114 -0
  52. data/lib/pry/commands/ls/constants.rb +47 -0
  53. data/lib/pry/commands/ls/formatter.rb +49 -0
  54. data/lib/pry/commands/ls/globals.rb +48 -0
  55. data/lib/pry/commands/ls/grep.rb +21 -0
  56. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  57. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  58. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  59. data/lib/pry/commands/ls/local_names.rb +35 -0
  60. data/lib/pry/commands/ls/local_vars.rb +39 -0
  61. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  62. data/lib/pry/commands/ls/methods.rb +57 -0
  63. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  64. data/lib/pry/commands/ls/self_methods.rb +32 -0
  65. data/lib/pry/commands/nesting.rb +25 -0
  66. data/lib/pry/commands/play.rb +103 -0
  67. data/lib/pry/commands/pry_backtrace.rb +25 -0
  68. data/lib/pry/commands/pry_version.rb +17 -0
  69. data/lib/pry/commands/raise_up.rb +32 -0
  70. data/lib/pry/commands/reload_code.rb +62 -0
  71. data/lib/pry/commands/reset.rb +18 -0
  72. data/lib/pry/commands/ri.rb +60 -0
  73. data/lib/pry/commands/save_file.rb +61 -0
  74. data/lib/pry/commands/shell_command.rb +48 -0
  75. data/lib/pry/commands/shell_mode.rb +25 -0
  76. data/lib/pry/commands/show_doc.rb +83 -0
  77. data/lib/pry/commands/show_info.rb +195 -0
  78. data/lib/pry/commands/show_input.rb +17 -0
  79. data/lib/pry/commands/show_source.rb +50 -0
  80. data/lib/pry/commands/simple_prompt.rb +22 -0
  81. data/lib/pry/commands/stat.rb +40 -0
  82. data/lib/pry/commands/switch_to.rb +23 -0
  83. data/lib/pry/commands/toggle_color.rb +24 -0
  84. data/lib/pry/commands/watch_expression.rb +105 -0
  85. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  86. data/lib/pry/commands/whereami.rb +190 -0
  87. data/lib/pry/commands/wtf.rb +57 -0
  88. data/lib/pry/config.rb +20 -229
  89. data/lib/pry/config/behavior.rb +139 -0
  90. data/lib/pry/config/convenience.rb +26 -0
  91. data/lib/pry/config/default.rb +165 -0
  92. data/lib/pry/core_extensions.rb +59 -38
  93. data/lib/pry/editor.rb +133 -0
  94. data/lib/pry/exceptions.rb +77 -0
  95. data/lib/pry/helpers.rb +1 -0
  96. data/lib/pry/helpers/base_helpers.rb +40 -154
  97. data/lib/pry/helpers/command_helpers.rb +19 -130
  98. data/lib/pry/helpers/documentation_helpers.rb +21 -11
  99. data/lib/pry/helpers/table.rb +109 -0
  100. data/lib/pry/helpers/text.rb +8 -9
  101. data/lib/pry/history.rb +61 -45
  102. data/lib/pry/history_array.rb +11 -1
  103. data/lib/pry/hooks.rb +10 -32
  104. data/lib/pry/indent.rb +110 -38
  105. data/lib/pry/input_completer.rb +242 -0
  106. data/lib/pry/input_lock.rb +132 -0
  107. data/lib/pry/inspector.rb +27 -0
  108. data/lib/pry/last_exception.rb +61 -0
  109. data/lib/pry/method.rb +199 -200
  110. data/lib/pry/method/disowned.rb +53 -0
  111. data/lib/pry/method/patcher.rb +125 -0
  112. data/lib/pry/method/weird_method_locator.rb +186 -0
  113. data/lib/pry/module_candidate.rb +39 -33
  114. data/lib/pry/object_path.rb +82 -0
  115. data/lib/pry/output.rb +50 -0
  116. data/lib/pry/pager.rb +234 -0
  117. data/lib/pry/plugins.rb +4 -3
  118. data/lib/pry/prompt.rb +26 -0
  119. data/lib/pry/pry_class.rb +199 -227
  120. data/lib/pry/pry_instance.rb +344 -403
  121. data/lib/pry/rbx_path.rb +1 -1
  122. data/lib/pry/repl.rb +202 -0
  123. data/lib/pry/repl_file_loader.rb +20 -26
  124. data/lib/pry/rubygem.rb +82 -0
  125. data/lib/pry/terminal.rb +79 -0
  126. data/lib/pry/test/helper.rb +170 -0
  127. data/lib/pry/version.rb +1 -1
  128. data/lib/pry/wrapped_module.rb +133 -48
  129. metadata +132 -197
  130. data/.document +0 -2
  131. data/.gemtest +0 -0
  132. data/.gitignore +0 -16
  133. data/.travis.yml +0 -17
  134. data/.yardopts +0 -1
  135. data/CHANGELOG +0 -387
  136. data/CONTRIBUTORS +0 -36
  137. data/Gemfile +0 -2
  138. data/Rakefile +0 -137
  139. data/TODO +0 -117
  140. data/examples/example_basic.rb +0 -15
  141. data/examples/example_command_override.rb +0 -32
  142. data/examples/example_commands.rb +0 -36
  143. data/examples/example_hooks.rb +0 -9
  144. data/examples/example_image_edit.rb +0 -67
  145. data/examples/example_input.rb +0 -7
  146. data/examples/example_input2.rb +0 -29
  147. data/examples/example_output.rb +0 -11
  148. data/examples/example_print.rb +0 -6
  149. data/examples/example_prompt.rb +0 -9
  150. data/examples/helper.rb +0 -6
  151. data/lib/pry/completion.rb +0 -221
  152. data/lib/pry/custom_completions.rb +0 -6
  153. data/lib/pry/default_commands/cd.rb +0 -81
  154. data/lib/pry/default_commands/commands.rb +0 -62
  155. data/lib/pry/default_commands/context.rb +0 -98
  156. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  157. data/lib/pry/default_commands/editing.rb +0 -420
  158. data/lib/pry/default_commands/find_method.rb +0 -169
  159. data/lib/pry/default_commands/gems.rb +0 -84
  160. data/lib/pry/default_commands/gist.rb +0 -187
  161. data/lib/pry/default_commands/help.rb +0 -127
  162. data/lib/pry/default_commands/hist.rb +0 -120
  163. data/lib/pry/default_commands/input_and_output.rb +0 -306
  164. data/lib/pry/default_commands/introspection.rb +0 -410
  165. data/lib/pry/default_commands/ls.rb +0 -272
  166. data/lib/pry/default_commands/misc.rb +0 -38
  167. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  168. data/lib/pry/default_commands/whereami.rb +0 -92
  169. data/lib/pry/extended_commands/experimental.rb +0 -7
  170. data/lib/pry/rbx_method.rb +0 -13
  171. data/man/pry.1 +0 -195
  172. data/man/pry.1.html +0 -204
  173. data/man/pry.1.ronn +0 -141
  174. data/pry.gemspec +0 -46
  175. data/test/candidate_helper1.rb +0 -11
  176. data/test/candidate_helper2.rb +0 -8
  177. data/test/helper.rb +0 -223
  178. data/test/test_cli.rb +0 -78
  179. data/test/test_code.rb +0 -201
  180. data/test/test_command.rb +0 -712
  181. data/test/test_command_helpers.rb +0 -9
  182. data/test/test_command_integration.rb +0 -668
  183. data/test/test_command_set.rb +0 -610
  184. data/test/test_completion.rb +0 -62
  185. data/test/test_control_d_handler.rb +0 -45
  186. data/test/test_default_commands/example.erb +0 -5
  187. data/test/test_default_commands/test_cd.rb +0 -318
  188. data/test/test_default_commands/test_context.rb +0 -280
  189. data/test/test_default_commands/test_documentation.rb +0 -314
  190. data/test/test_default_commands/test_find_method.rb +0 -50
  191. data/test/test_default_commands/test_gems.rb +0 -18
  192. data/test/test_default_commands/test_help.rb +0 -57
  193. data/test/test_default_commands/test_input.rb +0 -428
  194. data/test/test_default_commands/test_introspection.rb +0 -511
  195. data/test/test_default_commands/test_ls.rb +0 -151
  196. data/test/test_default_commands/test_shell.rb +0 -343
  197. data/test/test_default_commands/test_show_source.rb +0 -432
  198. data/test/test_exception_whitelist.rb +0 -21
  199. data/test/test_history_array.rb +0 -65
  200. data/test/test_hooks.rb +0 -521
  201. data/test/test_indent.rb +0 -277
  202. data/test/test_input_stack.rb +0 -86
  203. data/test/test_method.rb +0 -401
  204. data/test/test_pry.rb +0 -463
  205. data/test/test_pry_defaults.rb +0 -419
  206. data/test/test_pry_history.rb +0 -84
  207. data/test/test_pry_output.rb +0 -41
  208. data/test/test_sticky_locals.rb +0 -155
  209. data/test/test_syntax_checking.rb +0 -65
  210. data/test/test_wrapped_module.rb +0 -174
  211. data/test/testrc +0 -2
  212. data/test/testrcbad +0 -2
  213. data/wiki/Customizing-pry.md +0 -397
  214. data/wiki/Home.md +0 -4
@@ -0,0 +1,139 @@
1
+ module Pry::Config::Behavior
2
+ ASSIGNMENT = "=".freeze
3
+ NODUP = [TrueClass, FalseClass, NilClass, Symbol, Numeric, Module, Proc].freeze
4
+ INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/
5
+
6
+ module Builder
7
+ def from_hash(hash, default = nil)
8
+ new(default).tap do |config|
9
+ config.merge!(hash)
10
+ end
11
+ end
12
+ end
13
+
14
+ def self.included(klass)
15
+ unless defined?(RESERVED_KEYS)
16
+ const_set :RESERVED_KEYS, instance_methods(false).map(&:to_s).freeze
17
+ end
18
+ klass.extend(Builder)
19
+ end
20
+
21
+ def initialize(default = Pry.config)
22
+ @default = default
23
+ @lookup = {}
24
+ end
25
+
26
+ #
27
+ # @return [Pry::Config::Behavior]
28
+ # returns the default used if a matching value for a key isn't found in self
29
+ #
30
+ def default
31
+ @default
32
+ end
33
+
34
+ def [](key)
35
+ @lookup[key.to_s]
36
+ end
37
+
38
+ def []=(key, value)
39
+ key = key.to_s
40
+ if RESERVED_KEYS.include?(key)
41
+ raise ArgumentError, "few things are reserved by pry, but using '#{key}' as a configuration key is."
42
+ end
43
+ @lookup[key] = value
44
+ end
45
+
46
+ def method_missing(name, *args, &block)
47
+ key = name.to_s
48
+ if key[-1] == ASSIGNMENT
49
+ short_key = key[0..-2]
50
+ self[short_key] = args[0]
51
+ elsif key?(key)
52
+ self[key]
53
+ elsif @default.respond_to?(name)
54
+ value = @default.public_send(name, *args, &block)
55
+ # FIXME: refactor Pry::Hook so that it stores config on the config object,
56
+ # so that we can use the normal strategy.
57
+ self[key] = value.dup if key == 'hooks'
58
+ value
59
+ else
60
+ nil
61
+ end
62
+ end
63
+
64
+ def merge!(other)
65
+ other = try_convert_to_hash(other)
66
+ raise TypeError, "unable to convert argument into a Hash" unless other
67
+ other.each do |key, value|
68
+ self[key] = value
69
+ end
70
+ end
71
+
72
+ def ==(other)
73
+ @lookup == try_convert_to_hash(other)
74
+ end
75
+ alias_method :eql?, :==
76
+
77
+ def respond_to_missing?(key, include_private=false)
78
+ key?(key) or @default.respond_to?(key) or super(key, include_private)
79
+ end
80
+
81
+ def key?(key)
82
+ key = key.to_s
83
+ @lookup.key?(key)
84
+ end
85
+
86
+ def clear
87
+ @lookup.clear
88
+ true
89
+ end
90
+ alias_method :refresh, :clear
91
+
92
+ def forget(key)
93
+ @lookup.delete(key.to_s)
94
+ end
95
+
96
+ def keys
97
+ @lookup.keys
98
+ end
99
+
100
+ def to_hash
101
+ @lookup.dup
102
+ end
103
+ alias_method :to_h, :to_hash
104
+
105
+
106
+ def inspect
107
+ key_str = keys.map { |key| "'#{key}'" }.join(",")
108
+ "#<#{_clip_inspect(self)} local_keys=[#{key_str}] default=#{@default.inspect}>"
109
+ end
110
+
111
+ def pretty_print(q)
112
+ q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
113
+ end
114
+
115
+ private
116
+ def _clip_inspect(obj)
117
+ "#{obj.class}:0x%x" % obj.object_id << 1
118
+ end
119
+
120
+ def _dup(value)
121
+ if NODUP.any? { |klass| klass === value }
122
+ value
123
+ else
124
+ value.dup
125
+ end
126
+ end
127
+
128
+ def try_convert_to_hash(obj)
129
+ if Hash === obj
130
+ obj
131
+ elsif obj.respond_to?(:to_h)
132
+ obj.to_h
133
+ elsif obj.respond_to?(:to_hash)
134
+ obj.to_hash
135
+ else
136
+ nil
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,26 @@
1
+ module Pry::Config::Convenience
2
+ SHORTCUTS = [
3
+ :input,
4
+ :output,
5
+ :commands,
6
+ :print,
7
+ :exception_handler,
8
+ :quiet?,
9
+ :hooks,
10
+ :color,
11
+ :pager,
12
+ :editor,
13
+ :memory_size,
14
+ :extra_sticky_locals
15
+ ]
16
+
17
+
18
+ def config_shortcut(*names)
19
+ names.each do |name|
20
+ reader = name
21
+ setter = "#{name}="
22
+ define_method(reader) { config.public_send(name) }
23
+ define_method(setter) { |value| config.public_send(setter, value) }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,165 @@
1
+ class Pry::Config::Default
2
+ include Pry::Config::Behavior
3
+
4
+ default = {
5
+ input: proc {
6
+ lazy_readline
7
+ },
8
+ output: proc {
9
+ $stdout
10
+ },
11
+ commands: proc {
12
+ Pry::Commands
13
+ },
14
+ prompt_name: proc {
15
+ Pry::DEFAULT_PROMPT_NAME
16
+ },
17
+ prompt: proc {
18
+ Pry::DEFAULT_PROMPT
19
+ },
20
+ prompt_safe_objects: proc {
21
+ Pry::DEFAULT_PROMPT_SAFE_OBJECTS
22
+ },
23
+ print: proc {
24
+ Pry::DEFAULT_PRINT
25
+ },
26
+ quiet: proc {
27
+ false
28
+ },
29
+ exception_handler: proc {
30
+ Pry::DEFAULT_EXCEPTION_HANDLER
31
+ },
32
+ exception_whitelist: proc {
33
+ Pry::DEFAULT_EXCEPTION_WHITELIST
34
+ },
35
+ hooks: proc {
36
+ Pry::DEFAULT_HOOKS
37
+ },
38
+ pager: proc {
39
+ true
40
+ },
41
+ system: proc {
42
+ Pry::DEFAULT_SYSTEM
43
+ },
44
+ color: proc {
45
+ Pry::Helpers::BaseHelpers.use_ansi_codes?
46
+ },
47
+ default_window_size: proc {
48
+ 5
49
+ },
50
+ editor: proc {
51
+ Pry.default_editor_for_platform
52
+ }, # TODO: Pry::Platform.editor
53
+ should_load_rc: proc {
54
+ true
55
+ },
56
+ should_load_local_rc: proc {
57
+ true
58
+ },
59
+ should_trap_interrupts: proc {
60
+ Pry::Helpers::BaseHelpers.jruby?
61
+ }, # TODO: Pry::Platform.jruby?
62
+ disable_auto_reload: proc {
63
+ false
64
+ },
65
+ command_prefix: proc {
66
+ ""
67
+ },
68
+ auto_indent: proc {
69
+ Pry::Helpers::BaseHelpers.use_ansi_codes?
70
+ },
71
+ correct_indent: proc {
72
+ true
73
+ },
74
+ collision_warning: proc {
75
+ false
76
+ },
77
+ output_prefix: proc {
78
+ "=> "
79
+ },
80
+ requires: proc {
81
+ []
82
+ },
83
+ should_load_requires: proc {
84
+ true
85
+ },
86
+ should_load_plugins: proc {
87
+ true
88
+ },
89
+ windows_console_warning: proc {
90
+ true
91
+ },
92
+ control_d_handler: proc {
93
+ Pry::DEFAULT_CONTROL_D_HANDLER
94
+ },
95
+ memory_size: proc {
96
+ 100
97
+ },
98
+ extra_sticky_locals: proc {
99
+ {}
100
+ },
101
+ command_completions: proc {
102
+ proc { commands.keys }
103
+ },
104
+ file_completions: proc {
105
+ proc { Dir["."] }
106
+ },
107
+ ls: proc {
108
+ Pry::Config.from_hash(Pry::Command::Ls::DEFAULT_OPTIONS)
109
+ },
110
+ completer: proc {
111
+ require "pry/input_completer"
112
+ Pry::InputCompleter
113
+ }
114
+ }
115
+
116
+ def initialize
117
+ super(nil)
118
+ configure_gist
119
+ configure_history
120
+ end
121
+
122
+ def quiet?
123
+ quiet
124
+ end
125
+
126
+ default.each do |key, value|
127
+ define_method(key) do
128
+ if default[key].equal?(value)
129
+ default[key] = instance_eval(&value)
130
+ end
131
+ default[key]
132
+ end
133
+ end
134
+
135
+ private
136
+ # TODO:
137
+ # all of this configure_* stuff is a relic of old code.
138
+ # we should try move this code to being command-local.
139
+ def configure_gist
140
+ self["gist"] = Pry::Config.from_hash(inspecter: proc(&:pretty_inspect))
141
+ end
142
+
143
+ def configure_history
144
+ self["history"] = Pry::Config.from_hash "should_save" => true,
145
+ "should_load" => true
146
+ history.file = File.expand_path("~/.pry_history") rescue nil
147
+ if history.file.nil?
148
+ self.should_load_rc = false
149
+ history.should_save = false
150
+ history.should_load = false
151
+ end
152
+ end
153
+
154
+ def lazy_readline
155
+ require 'readline'
156
+ Readline
157
+ rescue LoadError
158
+ warn "Sorry, you can't use Pry without Readline or a compatible library."
159
+ warn "Possible solutions:"
160
+ warn " * Rebuild Ruby with Readline support using `--with-readline`"
161
+ warn " * Use the rb-readline gem, which is a pure-Ruby port of Readline"
162
+ warn " * Use the pry-coolline gem, a pure-ruby alternative to Readline"
163
+ raise
164
+ end
165
+ end
@@ -1,3 +1,24 @@
1
+ class Pry
2
+ # @return [Array] Code of the method used when implementing Pry's
3
+ # __binding__, along with line indication to be used with instance_eval (and
4
+ # friends).
5
+ #
6
+ # @see Object#__binding__
7
+ BINDING_METHOD_IMPL = [<<-METHOD, __FILE__, __LINE__ + 1]
8
+ # Get a binding with 'self' set to self, and no locals.
9
+ #
10
+ # The default definee is determined by the context in which the
11
+ # definition is eval'd.
12
+ #
13
+ # Please don't call this method directly, see {__binding__}.
14
+ #
15
+ # @return [Binding]
16
+ def __pry__
17
+ binding
18
+ end
19
+ METHOD
20
+ end
21
+
1
22
  class Object
2
23
  # Start a Pry REPL on self.
3
24
  #
@@ -45,66 +66,66 @@ class Object
45
66
  #
46
67
  # @return [Binding]
47
68
  def __binding__
69
+ # If you ever feel like changing this method, be careful about variables
70
+ # that you use. They shouldn't be inserted into the binding that will
71
+ # eventually be returning.
72
+
48
73
  # When you're cd'd into a class, methods you define should be added to it.
49
74
  if is_a?(Module)
50
75
  # class_eval sets both self and the default definee to this class.
51
76
  return class_eval "binding"
52
77
  end
53
78
 
54
- unless respond_to?(:__binding_impl__)
55
- binding_impl_method = [<<-METHOD, __FILE__, __LINE__ + 1]
56
- # Get a binding with 'self' set to self, and no locals.
57
- #
58
- # The default definee is determined by the context in which the
59
- # definition is eval'd.
60
- #
61
- # Please don't call this method directly, see {__binding__}.
62
- #
63
- # @return [Binding]
64
- def __binding_impl__
65
- binding
66
- end
67
- METHOD
68
-
79
+ unless respond_to?(:__pry__)
69
80
  # The easiest way to check whether an object has a working singleton class
70
81
  # is to try and define a method on it. (just checking for the presence of
71
82
  # the singleton class gives false positives for `true` and `false`).
72
- # __binding_impl__ is just the closest method we have to hand, and using
83
+ # __pry__ is just the closest method we have to hand, and using
73
84
  # it has the nice property that we can memoize this check.
74
85
  begin
75
86
  # instance_eval sets the default definee to the object's singleton class
76
- instance_eval(*binding_impl_method)
87
+ instance_eval(*Pry::BINDING_METHOD_IMPL)
77
88
 
78
89
  # If we can't define methods on the Object's singleton_class. Then we fall
79
90
  # back to setting the default definee to be the Object's class. That seems
80
91
  # nicer than having a REPL in which you can't define methods.
81
- rescue TypeError
92
+ rescue TypeError, Pry::FrozenObjectException
82
93
  # class_eval sets the default definee to self.class
83
- self.class.class_eval(*binding_impl_method)
94
+ self.class.class_eval(*Pry::BINDING_METHOD_IMPL)
84
95
  end
85
96
  end
86
97
 
87
- __binding_impl__
98
+ __pry__
88
99
  end
89
100
  end
90
101
 
91
- # There's a splat bug on jruby in 1.9 emulation mode, which breaks the
92
- # pp library.
93
- #
94
- # * http://jira.codehaus.org/browse/JRUBY-6687
95
- # * https://github.com/pry/pry/issues/568
96
- #
97
- # Until that gets fixed upstream, let's monkey-patch here:
98
- if [[1, 2]].pretty_inspect == "[1]\n"
99
- class Array
100
- def pretty_print(q)
101
- q.group(1, '[', ']') {
102
- i = 0
103
- q.seplist(self) { |*|
104
- q.pp self[i]
105
- i += 1
106
- }
107
- }
108
- end
102
+ class BasicObject
103
+ # Return a binding object for the receiver.
104
+ #
105
+ # The `self` of the binding is set to the current object, and it contains no
106
+ # local variables.
107
+ #
108
+ # The default definee (http://yugui.jp/articles/846) is set such that new
109
+ # methods defined will be added to the singleton class of the BasicObject.
110
+ #
111
+ # @return [Binding]
112
+ def __binding__
113
+ # BasicObjects don't have respond_to?, so we just define the method
114
+ # every time. As they also don't have `.freeze`, this call won't
115
+ # fail as it can for normal Objects.
116
+ (class << self; self; end).class_eval <<-EOF, __FILE__, __LINE__ + 1
117
+ # Get a binding with 'self' set to self, and no locals.
118
+ #
119
+ # The default definee is determined by the context in which the
120
+ # definition is eval'd.
121
+ #
122
+ # Please don't call this method directly, see {__binding__}.
123
+ #
124
+ # @return [Binding]
125
+ def __pry__
126
+ ::Kernel.binding
127
+ end
128
+ EOF
129
+ self.__pry__
109
130
  end
110
131
  end