fsck 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/README.md +20 -2
- data/bench.rb +21 -0
- data/lib/fsck/version.rb +1 -1
- data/lib/fsck.rb +9 -8
- metadata +4 -3
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,6 +6,7 @@ Fsck allows you to express your feelings while you're developing. It does this b
|
|
6
6
|
gem install fsck
|
7
7
|
|
8
8
|
## Examples
|
9
|
+
|
9
10
|
Fsck allows you to have a sense of closure during your everyday development life. Here's some examples:
|
10
11
|
|
11
12
|
*A difficult problem causing you frustration? Tell it how you feel.*
|
@@ -20,7 +21,9 @@ Fsck allows you to have a sense of closure during your everyday development life
|
|
20
21
|
(1..10).awesome_inject_is_awesome(&:+)
|
21
22
|
|
22
23
|
## Usage
|
23
|
-
|
24
|
+
|
25
|
+
### Spot Usage
|
26
|
+
|
24
27
|
Fsck comes as a module that you can include wherever you want.
|
25
28
|
|
26
29
|
require "fsck"
|
@@ -36,18 +39,33 @@ Fsck comes as a module that you can include wherever you want.
|
|
36
39
|
my_object = MyClass.new
|
37
40
|
my_object.calling_my_awesome_method # => 42
|
38
41
|
|
39
|
-
|
42
|
+
### Deep Usage
|
43
|
+
|
40
44
|
Fsck also provides a way to use its functionality on every object in ruby.
|
41
45
|
|
42
46
|
require "fsck/deep"
|
43
47
|
|
44
48
|
42.gimme_succ # => 43
|
45
49
|
ary = Array.new_array_please # => []
|
50
|
+
|
51
|
+
## Fsck: How does it work?
|
52
|
+
|
53
|
+
Fsck achieves its functionality by greatly abusing `method_missing`. Each time a fscked method is called, every method defined on the object is examined. The method with the longest name is assumed to be the *intended* method.
|
54
|
+
|
55
|
+
The examination process splits the word of each method name, building a regex that allows for any number of other words to be inserted wherever. If you aren't careful with the words you choose, you may unintentionally call another method.
|
56
|
+
|
57
|
+
# you may expect this to call #each, but it will instead call #each_value
|
58
|
+
my_hash.what_i_need_is_each_set_of_key_plus_value { |k,v| puts k }
|
46
59
|
|
47
60
|
## Origin
|
61
|
+
|
48
62
|
Fsck is named after the use of the Unix file system utility, specifically as it is applied to [profanity](http://en.wikipedia.org/wiki/Fsck#Use_as_profanity).
|
49
63
|
|
50
64
|
**NOTE:** This gem has nothing to do with the Unix file system utility
|
51
65
|
|
66
|
+
## Disclaimer
|
67
|
+
|
68
|
+
Your application will take a more than trivial performance hit if you use this gem. The benchmark I ran on Fixnum (bench.rb) shows that using a fscked method is roughly 20 times slower. This only tests the performance of repeated fscked method calls (which should be most common use). If you're dynamically building a fscked method call based on some variable, you can expect much worse performance. Use at your own risk.
|
69
|
+
|
52
70
|
## License
|
53
71
|
MIT License. Copyright 2011 Chris Thorn.
|
data/bench.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "lib")
|
2
|
+
|
3
|
+
require "benchmark"
|
4
|
+
require "fsck/deep"
|
5
|
+
|
6
|
+
N = 1_000
|
7
|
+
|
8
|
+
Benchmark.bm(10) do |r|
|
9
|
+
r.report("vanilla") { N.times { 42.succ } }
|
10
|
+
r.report("fscked") { N.times { 42.gimme_succ_please } }
|
11
|
+
end
|
12
|
+
|
13
|
+
# v0.0.3
|
14
|
+
# user system total real
|
15
|
+
# vanilla 0.000000 0.000000 0.000000 ( 0.000246)
|
16
|
+
# fscked 0.010000 0.000000 0.010000 ( 0.005068)
|
17
|
+
|
18
|
+
# results on my machine (v0.0.2)
|
19
|
+
# user system total real
|
20
|
+
# vanilla 0.000000 0.000000 0.000000 ( 0.000130)
|
21
|
+
# fscked 2.960000 0.090000 3.050000 ( 3.053142)
|
data/lib/fsck/version.rb
CHANGED
data/lib/fsck.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fsck
|
2
2
|
def method_missing(sym, *args, &block)
|
3
|
+
@_fsck_method_name_cache ||= {}
|
4
|
+
|
5
|
+
return send(@_fsck_method_name_cache[sym], *args, &block) if @_fsck_method_name_cache[sym]
|
6
|
+
|
3
7
|
fscked_method = sym.to_s
|
4
8
|
|
5
9
|
if punctuation = fscked_method[/[!?=]$/]
|
@@ -7,23 +11,20 @@ module Fsck
|
|
7
11
|
end
|
8
12
|
|
9
13
|
matches = methods.select do |m|
|
10
|
-
fscked_method =~ /^#{
|
14
|
+
fscked_method =~ /^#{__fsck_method_regex_str__(m)}#{punctuation}$/
|
11
15
|
end
|
12
16
|
|
13
17
|
if matches.empty?
|
14
18
|
super
|
15
19
|
else
|
16
|
-
|
20
|
+
@_fsck_method_name_cache[sym] = matches.sort_by(&:length).last
|
21
|
+
send(@_fsck_method_name_cache[sym], *args, &block)
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
20
25
|
private
|
21
|
-
def
|
22
|
-
@_fsck_method_name_cache ||= {}
|
23
|
-
|
24
|
-
return @_fsck_method_name_cache[method] if @_fsck_method_name_cache[method]
|
25
|
-
|
26
|
+
def __fsck_method_regex_str__(method)
|
26
27
|
words = method.to_s.delete("!?=").split("_").map { |w| Regexp.escape(w) }
|
27
|
-
|
28
|
+
"(\\w*_)?#{words.join('\w*_\w*')}(_\\w*)?"
|
28
29
|
end
|
29
30
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Chris Thorn
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-06 00:00:00 -09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- Gemfile.lock
|
48
48
|
- README.md
|
49
49
|
- Rakefile
|
50
|
+
- bench.rb
|
50
51
|
- fsck.gemspec
|
51
52
|
- lib/fsck.rb
|
52
53
|
- lib/fsck/deep.rb
|