-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot.pryrc
42 lines (37 loc) · 1.06 KB
/
dot.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
# coding: utf-8
Pry.config.prompt = [
proc {|target_self, nest_level, pry|
nested = (nest_level.zero?) ? '' : ":#{nest_level}"
"[#{pry.input_array.size}] #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}(#{Pry.view_clip(target_self)})#{nested}> "
},
proc {|target_self, nest_level, pry|
nested = (nest_level.zero?) ? '' : ":#{nest_level}"
"[#{pry.input_array.size}] #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}(#{Pry.view_clip(target_self)})#{nested}* "
}
]
##
# My methods
class Object
def my_methods_only
my_super = self.class.superclass
my_super ? methods - my_super.instance_methods : methods
end
def my_methods_only_no_mixins
self.class.ancestors.inject(methods) do |mlist, ancestor|
mlist = mlist - ancestor.instance_methods unless ancestor.is_a? Class
mlist
end
end
end
##
# Utils
def levenshtein_distance(s, t)
t.chars.with_index.inject(0..s.size) do |r, (a, z)|
z += 1
[z] + s.chars.zip(r.each_cons(2)).map do |b, (x, y)|
z = [y + 1, z + 1, x + (a == b ? 0 : 1)].min
end
end.last
end
# __END__
# vim: filetype=ruby