Module: Kernel

Defined in:
lib/pryx/looksee_hack.rb,
lib/pryx/irb_hack.rb,
lib/pryx/pry_hack.rb

Overview

ls1 支持的参数有:

  • String 或 Regexp,包含字符串或匹配正则过滤.

  • :nopublic :noprotected, :noprivate, :noundefined, :nooverridden 显示指定类型方法.

颜色方案模块 白色 37 公开方法 绿色 32 保护方法 黄色 33 私有方法 红色 31 取消定义的方法 蓝色 34 被覆写的方法 灰色 30

Instance Method Summary collapse

Instance Method Details

#irb!Object



24
25
26
27
28
29
30
# File 'lib/pryx/irb_hack.rb', line 24

def irb!
  return unless ENV['IRB_was_started'].nil?

  ENV['IRB_was_started'] = 'true'

  binding.of_caller(1)._irb
end

#irb1Object



36
37
38
# File 'lib/pryx/irb_hack.rb', line 36

def irb1
  ENV['IRB2_should_start'] = 'true'
end

#irb2(caller = 1, remote: nil, port: 9876) ⇒ Object



40
41
42
43
44
45
# File 'lib/pryx/irb_hack.rb', line 40

def irb2(caller=1, remote: nil, port: 9876)
  if ENV['IRB2_should_start'] == 'true'
    ENV['IRB2_should_start'] = nil
    binding.of_caller(caller)._irb
  end
end

#load_lookseeObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pryx/looksee_hack.rb', line 13

def load_looksee
  case RbConfig::CONFIG['ruby_version']
  when '1.9.0'...'2.1.0'
    require 'old_looksee'
  when '2.1.0'...'3.2.0'
    require 'looksee'
  end
  Looksee.rename :ls_looksee

  Looksee.editor = '.emacsclient +%l %f' # e.g. [].ls1.edit :to_set
end

#ls1(*args) ⇒ Object



25
26
27
28
# File 'lib/pryx/looksee_hack.rb', line 25

def ls1(*args)
  load_looksee unless defined? Looksee
  Looksee[self, *args, :noprivate]
end

#ls2(*args) ⇒ Object



30
31
32
33
# File 'lib/pryx/looksee_hack.rb', line 30

def ls2(*args)
  load_looksee unless defined? Looksee
  Looksee[self, *args]
end

#notify_send(msg) ⇒ Object



103
104
105
106
107
108
# File 'lib/pryx/pry_hack.rb', line 103

def notify_send(msg)
  system("notify-send \"#{msg}\"") if system 'which notify-send &>/dev/null'

  system('aplay "#{__dir__}/drip.wav" &>/dev/null') if system 'which aplay &>/dev/null'
  warn "#{msg}"
end

#pry!(remote: nil, port: 9876) ⇒ Object

运行 pry! 会被拦截, 且只会被拦截一次.



53
54
55
56
57
58
59
60
61
# File 'lib/pryx/pry_hack.rb', line 53

def pry!(remote: nil, port: 9876)
  return unless ENV['Pry_was_started'].nil?

  ENV['Pry_was_started'] = 'true'

  pry3(2, remote: remote, port: port)

  # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空.
end

#pry1Object



89
90
91
# File 'lib/pryx/pry_hack.rb', line 89

def pry1
  ENV['Pry2_should_start'] = 'true'
end

#pry2(caller = 1, remote: nil, port: 9876) ⇒ Object

  1. 单独运行 pry2, 永远不会被拦截,

  2. 如果之前运行过 pry1, 此时 pry2 将被拦截, 且只会被拦截一次.



96
97
98
99
100
101
# File 'lib/pryx/pry_hack.rb', line 96

def pry2(caller=1, remote: nil, port: 9876)
  if ENV['Pry2_should_start'] == 'true'
    ENV['Pry2_should_start'] = nil
    binding.of_caller(caller)._pry(remote, port)
  end
end

#pry3(caller = 1, remote: nil, port: 9876) ⇒ Object

等价于默认的 binding.pry, 会反复被拦截。起成 pry3 这个名字,也是为了方便直接使用。



83
84
85
86
87
# File 'lib/pryx/pry_hack.rb', line 83

def pry3(caller=1, remote: nil, port: 9876)
  remote = '0.0.0.0' if Pryx::Background.background?

  binding.of_caller(caller)._pry(remote, port)
end

#pry?(remote: nil, port: 9876) ⇒ Boolean

和 pry! 的差别就是,pry? 使用 pry-state 插件输出当前 context 的很多变量内容。注意:不需要总是开启 pry-state,因为有时候会输出太多内容,造成刷屏。

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
78
79
# File 'lib/pryx/pry_hack.rb', line 70

def pry?(remote: nil, port: 9876)
  return unless ENV['Pry_was_started'].nil?

  require 'pry-state'
  ENV['Pry_was_started'] = 'true'

  pry3(2, remote: remote, port: port)

  # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空.
end

#reirb!Object



32
33
34
# File 'lib/pryx/irb_hack.rb', line 32

def reirb!
  ENV['IRB_was_started'] = nil
end

#repry!Object

在 pry! 之前如果输入这个,会让下次执行的 pry! 被拦截一次, 而不管之前是否有执行过 pry!



64
65
66
# File 'lib/pryx/pry_hack.rb', line 64

def repry!
  ENV['Pry_was_started'] = nil
end