prefix 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +14 -0
  2. data/prefix.rb +16 -0
  3. metadata +48 -0
@@ -0,0 +1,14 @@
1
+ This library implements two methods: `Array#~` and `Symbol#~`.
2
+ `Array#~` turns an `Array` into a `Set`.
3
+ `Symbol#~` turns a `Symbol` into a `respond_to?` matcher.
4
+
5
+ ``` ruby
6
+ case something
7
+ when ~:to_hash then ...
8
+ when ~:to_ary then ...
9
+ else ~[1, 2, 3]
10
+ end
11
+ ```
12
+
13
+ It not reach the [threshold of originality](http://en.wikipedia.org/wiki/Threshold_of_originality),
14
+ so no license is needed.
@@ -0,0 +1,16 @@
1
+ require 'set'
2
+ Array. send( :define_method, :~) { Set.new(self) } unless Array. method_defined? :~
3
+ Symbol. send( :define_method, :~) { proc { |a| a.respond_to? self } } unless Symbol. method_defined? :~
4
+ Proc. send( :alias_method, :===, :call) unless proc { true } === 42
5
+ eval(DATA.read, binding, __FILE__, __LINE__ + 2) if __FILE__ == $0
6
+ __END__
7
+
8
+ dummy = Struct.new(:foo).new(42)
9
+ fail unless ~[2, 1, 1] == Set[1, 2]
10
+ fail unless ~:foo === dummy
11
+
12
+ case dummy
13
+ when ~:bar then fail
14
+ when ~:foo then nil
15
+ else fail
16
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prefix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Konstantin Haase
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: adds ~ to Array and Symbol
15
+ email:
16
+ - konstantin.mailinglists@googlemail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - prefix.rb
22
+ - README.md
23
+ homepage: http://github.com/rkh/prefix
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - .
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.11
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: syntax for Set and respond_to matchers
47
+ test_files:
48
+ - prefix.rb