ampex 2.0.0 → 3.0.0

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.
Files changed (3) hide show
  1. data/README.markdown +14 -1
  2. data/lib/ampex.rb +14 -1
  3. metadata +7 -5
@@ -35,6 +35,15 @@ You can use this in any place a block is expected, for example to create a lambd
35
35
  normalizer.call :HelloWorld
36
36
  # => "helloworld"
37
37
 
38
+ Last but definitly not least you can use ampex in a case clause:
39
+
40
+ case something
41
+ when X.respond_to? :foo
42
+ something.foo
43
+ when X.respond_to? :[]
44
+ something['foo']
45
+ end
46
+
38
47
  Gotchas
39
48
  -------
40
49
 
@@ -83,10 +92,14 @@ Between version 1.2.1 and version 2.0.0, the support for assignment operations w
83
92
  ampex. These had a very non-obvious implementation, and it was impossible to support
84
93
  assigning of falsey values; and did not work on rubinius.
85
94
 
95
+ Between version 2.0.0 and 3.0.0 Metavariable#=== was implemented to provide case statement
96
+ support. This will break code that was expecting `&(X === foo)` to work.
97
+
86
98
  See also
87
99
  --------
88
100
 
89
- * <https://cirw.in/blog/ampex> — a blog post that describes the ideas.
101
+ * <http://cirw.in/blog/ampex> — a blog post that describes the ideas.
102
+ * <https://github.com/raganwald/homoiconic/blob/master/2012/05/anaphora.md#anaphora-in-ruby-2012-edition> — a detailed overview of all similar libraries available for Ruby.
90
103
  * <https://github.com/danielribeiro/RubyUnderscore> — which uses an underscore in place of `&X` and works by rewriting the syntax tree.
91
104
  * <https://gist.github.com/1224361> — a patch for Rubinius that enables the underscore in a similar way.
92
105
  * <http://blog.railsware.com/2012/03/13/ruby-2-0-enumerablelazy/> — The upcoming lazy enumerable support for Ruby 2.0.
@@ -23,6 +23,19 @@ class Metavariable < superclass
23
23
  @to_proc = block || ::Proc.new{|x| x}
24
24
  end
25
25
 
26
+ # This method is here so that a metavariable can be used as a target for "when" like this:
27
+ #
28
+ # case foo
29
+ # when X.respond_to? :bar
30
+ # "Responds to :bar"
31
+ # when X.respond_to? :foobar
32
+ # "Responds to :foobar"
33
+ # end
34
+ #
35
+ def ===(y)
36
+ !!to_proc.call(y)
37
+ end
38
+
26
39
  # Each time a method is called on a Metavariable, we want to create a new
27
40
  # Metavariable that is like the last but does something more.
28
41
  #
@@ -42,7 +55,7 @@ class Metavariable < superclass
42
55
  # BlankSlate and BasicObject have different sets of methods that you don't want.
43
56
  # let's remove them all.
44
57
  instance_methods.each do |method|
45
- undef_method method unless %w(method_missing to_proc __send__ __id__).include? method.to_s
58
+ undef_method method unless %w(method_missing to_proc __send__ __id__ ===).include? method.to_s
46
59
  end
47
60
  end
48
61
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ampex
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
- - 2
7
+ - 3
8
8
  - 0
9
9
  - 0
10
- version: 2.0.0
10
+ version: 3.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Conrad Irwin
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-20 00:00:00 Z
18
+ date: 2012-09-27 00:00:00 -07:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: blankslate
@@ -43,6 +44,7 @@ files:
43
44
  - lib/ampex.rb
44
45
  - README.markdown
45
46
  - LICENSE.MIT
47
+ has_rdoc: true
46
48
  homepage: http://github.com/rapportive-oss/ampex
47
49
  licenses: []
48
50
 
@@ -72,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  requirements: []
73
75
 
74
76
  rubyforge_project:
75
- rubygems_version: 1.8.21
77
+ rubygems_version: 1.6.2
76
78
  signing_key:
77
79
  specification_version: 3
78
80
  summary: Provides a meta-variable X which can be used to create procs more prettily