pry-syntax-hacks 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.markdown +6 -0
  2. data/lib/pry-syntax-hacks.rb +24 -0
  3. metadata +13 -11
@@ -20,6 +20,12 @@ Accessing method objects:
20
20
 
21
21
  pry (main)> ["foo@bar.com"].map &User.:find_by_email
22
22
 
23
+ Accessing outer Pry bindings:
24
+
25
+ pry (main)> cd (a = Object.new)
26
+ pry (main)> puts ../a
27
+ #<Object:0x195aca8>
28
+
23
29
  # Issues
24
30
 
25
31
  This will break regular expressions most often:
@@ -3,9 +3,33 @@ class Pry
3
3
 
4
4
  def retrieve_line(eval_string, *args)
5
5
  old_retrieve_line(eval_string, *args)
6
+ Pry.hack_line(eval_string)
7
+ end
6
8
 
9
+ def self.hack_line(eval_string)
7
10
  eval_string.gsub!(/\.(@[a-z0-9_]+)/, '.instance_variable_get("\1")')
8
11
  eval_string.gsub!(/\.:([a-z0-9_]+[?!]?)/, '.method(:\1)')
9
12
  eval_string.gsub!(/\.!([a-z0-9_]+[?!]?)([ \(])(?=(.*))/) { ".send#{$2}:#{$1}#{$3 == ""?"":","}" }
13
+ eval_string.gsub!(/(^|[\s\[{>(<=])((\.\.\/)+)([a-z0-9_@]+)/) { "#{$1}_pry_.binding_or_raise(#{-1 - $2.size / 3}).eval('#{$4}')" }
14
+ eval_string
15
+ end
16
+
17
+ def binding_or_raise(n)
18
+ binding_stack[n] or raise "no parent binding"
19
+ end
20
+
21
+ class Command
22
+ def target
23
+ unless @target.respond_to?(:unhacked_eval)
24
+ class << @target
25
+ alias_method :unhacked_eval, :eval
26
+
27
+ def eval(str, *args)
28
+ unhacked_eval(Pry.hack_line(str.dup), *args)
29
+ end
30
+ end
31
+ end
32
+ @target
33
+ end
10
34
  end
11
35
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-syntax-hacks
3
3
  version: !ruby/object:Gem::Version
4
- hash: 2495673787400639531
5
- prerelease:
4
+ hash: 21
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Conrad Irwin
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-28 00:00:00 Z
18
+ date: 2012-02-28 00:00:00 -08:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: pry
@@ -25,7 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
28
- hash: 1677717600019211762
29
+ hash: 43
29
30
  segments:
30
31
  - 0
31
32
  - 9
@@ -45,9 +46,10 @@ files:
45
46
  - lib/pry-syntax-hacks.rb
46
47
  - README.markdown
47
48
  - LICENSE.MIT
49
+ has_rdoc: true
48
50
  homepage: http://github.com/ConradIrwin/pry-syntax-hacks
49
- licenses: []
50
-
51
+ licenses:
52
+ - MIT
51
53
  post_install_message:
52
54
  rdoc_options: []
53
55
 
@@ -58,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
60
  requirements:
59
61
  - - ">="
60
62
  - !ruby/object:Gem::Version
61
- hash: 2002549777813010636
63
+ hash: 3
62
64
  segments:
63
65
  - 0
64
66
  version: "0"
@@ -67,14 +69,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
69
  requirements:
68
70
  - - ">="
69
71
  - !ruby/object:Gem::Version
70
- hash: 2002549777813010636
72
+ hash: 3
71
73
  segments:
72
74
  - 0
73
75
  version: "0"
74
76
  requirements: []
75
77
 
76
78
  rubyforge_project:
77
- rubygems_version: 1.8.12
79
+ rubygems_version: 1.3.7
78
80
  signing_key:
79
81
  specification_version: 3
80
82
  summary: Allows various short-cuts that make exploring Ruby objects nicer