-
Notifications
You must be signed in to change notification settings - Fork 3
/
pryrc
76 lines (64 loc) · 1.4 KB
/
pryrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- mode: ruby -*-
if ENV['TERM'] == 'dumb'
Pry.config.pager = false
Pry.config.editor = 'emacsclient'
else
Pry.config.editor = 'atom'
end
if defined?(PryByebug) || defined?(PryDebugger)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'f', 'finish'
end
require 'date'
require 'bigdecimal'
class Date
def inspect
"#<Date: #{self}>"
end
end
class BigDecimal
def inspect
"#{to_s('F')}bd"
end
end
class String
def to_proc
proc { |h| h[self] }
end
end
class Symbol
def to_proc
chain = to_s.split('__')
proc do |obj|
chain.reduce(obj) { |r, m| r.send(m) }
end
end
end
# cuz instance_variable_get() et al are too fkn long
class Object
def ivs
instance_variables
end
def iv(name)
name = "@#{name}" unless name.to_s.start_with?("@")
instance_variable_get(name)
end
def ivset(name, val)
name = "@#{name}" unless name.to_s.start_with?("@")
instance_variable_set(name, val)
end
end
def sizeof(target, seen = nil)
require 'objspace'
require 'set'
seen ||= Set.new
reachable = ObjectSpace.reachable_objects_from(target)
reachable.reduce(ObjectSpace.memsize_of(target)) do |sum, obj|
next sum if obj.is_a?(Module)
next sum if seen.member?(obj.object_id)
seen.add(obj.object_id)
sum += sizeof(obj, seen)
end
end