nkpart-prohax 1.0.2 → 1.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/Manifest.txt +4 -0
- data/README.txt +16 -7
- data/lib/prohax.rb +1 -1
- data/lib/prohax/let_in.rb +1 -7
- data/lib/prohax/metaclass.rb +7 -0
- data/lib/prohax/patches/enumerable.rb +44 -0
- data/lib/prohax/patches/symbol.rb +5 -0
- data/lib/prohax/strucked.rb +13 -5
- data/prohax.gemspec +3 -3
- data/spec/strucked_spec.rb +5 -1
- metadata +6 -2
data/Manifest.txt
CHANGED
@@ -7,12 +7,16 @@ coverage/index.html
|
|
7
7
|
coverage/lib-prohax-box_rb.html
|
8
8
|
coverage/lib-prohax-either_rb.html
|
9
9
|
coverage/lib-prohax-let_in_rb.html
|
10
|
+
coverage/lib-prohax-metaclass_rb.html
|
10
11
|
coverage/lib-prohax-strucked_rb.html
|
11
12
|
coverage/lib-prohax_rb.html
|
12
13
|
lib/prohax.rb
|
13
14
|
lib/prohax/box.rb
|
14
15
|
lib/prohax/either.rb
|
15
16
|
lib/prohax/let_in.rb
|
17
|
+
lib/prohax/metaclass.rb
|
18
|
+
lib/prohax/patches/enumerable.rb
|
19
|
+
lib/prohax/patches/symbol.rb
|
16
20
|
lib/prohax/strucked.rb
|
17
21
|
prohax.gemspec
|
18
22
|
script/console
|
data/README.txt
CHANGED
@@ -11,8 +11,17 @@ Just some hax that I use.
|
|
11
11
|
* Let-in - a neat syntax that's a bit like haskell. Contents of the hash supplied to `let()`
|
12
12
|
are defined as functions on a container, on which the block passed to `in` is instance_eval'd with.
|
13
13
|
|
14
|
-
|
14
|
+
let( :awesome => proc { |n| "#{n} is awesome." }).in { [1,2,3].map { |e| awesome(e) }
|
15
|
+
|
16
|
+
It can also be used to create mini dsl things like this:
|
17
|
+
|
18
|
+
def add a
|
19
|
+
let(:to => proc { |b| b + a })
|
20
|
+
end
|
15
21
|
|
22
|
+
add(5).to(3) # <= 8
|
23
|
+
|
24
|
+
|
16
25
|
* Strucked - a class builder, that just instantiates instance vars
|
17
26
|
|
18
27
|
# before
|
@@ -27,6 +36,12 @@ Just some hax that I use.
|
|
27
36
|
class Foo < Strucked.build(:a, :b)
|
28
37
|
end
|
29
38
|
|
39
|
+
# with readers
|
40
|
+
class Foo < Strucked.build(:a, :b).with_readers
|
41
|
+
end
|
42
|
+
|
43
|
+
Foo.new(5, 10).a # <= 5
|
44
|
+
|
30
45
|
* Kernel#either - a kind of either-like thing.
|
31
46
|
|
32
47
|
# If no exceptions are thrown, `failure` will be nil and `success` will be the result of the block.
|
@@ -39,12 +54,6 @@ Just some hax that I use.
|
|
39
54
|
success, failure = either { 5 }
|
40
55
|
success # <= 5
|
41
56
|
|
42
|
-
|
43
|
-
|
44
|
-
== SYNOPSIS:
|
45
|
-
|
46
|
-
FIX (code sample of usage)
|
47
|
-
|
48
57
|
== LICENSE:
|
49
58
|
|
50
59
|
(The MIT License)
|
data/lib/prohax.rb
CHANGED
data/lib/prohax/let_in.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Enumerable
|
2
|
+
def index_by &key_function
|
3
|
+
inject({}) do |accum, elem|
|
4
|
+
accum[key_function.call(elem)] = elem
|
5
|
+
accum
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def as_index_for &value_function
|
10
|
+
inject({}) do |accum, elem|
|
11
|
+
accum[elem] = value_function.call(elem)
|
12
|
+
accum
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def take_while &pred
|
17
|
+
result = []
|
18
|
+
each do |elem|
|
19
|
+
if (!pred.call(elem))
|
20
|
+
return result
|
21
|
+
end
|
22
|
+
result << elem
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def group_by &key_function
|
27
|
+
inject(Hash.new { |h,k| h[k] = [] }) do |hsh,elem|
|
28
|
+
hsh[key_function.call(elem)] << elem
|
29
|
+
hsh
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def grepv re
|
34
|
+
select { |s| s !~ re }
|
35
|
+
end
|
36
|
+
|
37
|
+
def zip_with arr, &blk
|
38
|
+
zip(arr).map(&blk)
|
39
|
+
end
|
40
|
+
|
41
|
+
def inject_with sym
|
42
|
+
inject { |a, b| a.send(sym, b) }
|
43
|
+
end
|
44
|
+
end
|
data/lib/prohax/strucked.rb
CHANGED
@@ -2,26 +2,34 @@
|
|
2
2
|
class Strucked
|
3
3
|
def self.build *fields
|
4
4
|
cls = Class.new
|
5
|
-
cls.class_eval
|
5
|
+
cls.class_eval <<-EOS
|
6
6
|
def self.fields
|
7
7
|
#{fields.inspect}
|
8
8
|
end
|
9
|
+
EOS
|
10
|
+
cls.class_eval {
|
11
|
+
def self.with_readers
|
12
|
+
fields.each do |f|
|
13
|
+
attr_reader f
|
14
|
+
end
|
15
|
+
self
|
16
|
+
end
|
9
17
|
|
10
18
|
def initialize *values
|
11
19
|
if self.class.fields.size != values.size
|
12
|
-
raise ArgumentError.new("Wrong number of arguments, expected
|
20
|
+
raise ArgumentError.new("Wrong number of arguments, expected #{self.class.fields.size} got #{values.size}")
|
13
21
|
end
|
14
22
|
self.class.fields.zip(values).each do |fld, value|
|
15
|
-
self.instance_variable_set("
|
23
|
+
self.instance_variable_set("@#{fld}", value)
|
16
24
|
end
|
17
25
|
end
|
18
26
|
|
19
27
|
def == other
|
20
28
|
self.class.fields.inject(true) do |memo, f|
|
21
|
-
memo && (self.instance_variable_get("
|
29
|
+
memo && (self.instance_variable_get("@#{f}") == other.instance_variable_get("@#{f}"))
|
22
30
|
end
|
23
31
|
end
|
24
|
-
|
32
|
+
}
|
25
33
|
cls
|
26
34
|
end
|
27
35
|
end
|
data/prohax.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{prohax}
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Nick Partridge"]
|
9
|
-
s.date = %q{2008-
|
9
|
+
s.date = %q{2008-12-10}
|
10
10
|
s.description = %q{}
|
11
11
|
s.email = ["nkpart@gmail.com"]
|
12
12
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.txt"]
|
13
|
-
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "coverage/index.html", "coverage/lib-prohax-box_rb.html", "coverage/lib-prohax-either_rb.html", "coverage/lib-prohax-let_in_rb.html", "coverage/lib-prohax-strucked_rb.html", "coverage/lib-prohax_rb.html", "lib/prohax.rb", "lib/prohax/box.rb", "lib/prohax/either.rb", "lib/prohax/let_in.rb", "lib/prohax/strucked.rb", "prohax.gemspec", "script/console", "script/destroy", "script/generate", "spec/box_spec.rb", "spec/either_spec.rb", "spec/let_in_syntax_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/strucked_spec.rb", "tasks/rspec.rake", "test_gem.sh"]
|
13
|
+
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "coverage/index.html", "coverage/lib-prohax-box_rb.html", "coverage/lib-prohax-either_rb.html", "coverage/lib-prohax-let_in_rb.html", "coverage/lib-prohax-metaclass_rb.html", "coverage/lib-prohax-strucked_rb.html", "coverage/lib-prohax_rb.html", "lib/prohax.rb", "lib/prohax/box.rb", "lib/prohax/either.rb", "lib/prohax/let_in.rb", "lib/prohax/metaclass.rb", "lib/prohax/patches/enumerable.rb", "lib/prohax/patches/symbol.rb", "lib/prohax/strucked.rb", "prohax.gemspec", "script/console", "script/destroy", "script/generate", "spec/box_spec.rb", "spec/either_spec.rb", "spec/let_in_syntax_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/strucked_spec.rb", "tasks/rspec.rake", "test_gem.sh"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/nkpart/prohax}
|
16
16
|
s.rdoc_options = ["--main", "README.txt"]
|
data/spec/strucked_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nkpart-prohax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Partridge
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-10 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -43,12 +43,16 @@ files:
|
|
43
43
|
- coverage/lib-prohax-box_rb.html
|
44
44
|
- coverage/lib-prohax-either_rb.html
|
45
45
|
- coverage/lib-prohax-let_in_rb.html
|
46
|
+
- coverage/lib-prohax-metaclass_rb.html
|
46
47
|
- coverage/lib-prohax-strucked_rb.html
|
47
48
|
- coverage/lib-prohax_rb.html
|
48
49
|
- lib/prohax.rb
|
49
50
|
- lib/prohax/box.rb
|
50
51
|
- lib/prohax/either.rb
|
51
52
|
- lib/prohax/let_in.rb
|
53
|
+
- lib/prohax/metaclass.rb
|
54
|
+
- lib/prohax/patches/enumerable.rb
|
55
|
+
- lib/prohax/patches/symbol.rb
|
52
56
|
- lib/prohax/strucked.rb
|
53
57
|
- prohax.gemspec
|
54
58
|
- script/console
|