my-sugar 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module MySugar
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/my-sugar.rb CHANGED
@@ -11,18 +11,23 @@ end
11
11
 
12
12
  include MySugar::Stuff # ah..
13
13
 
14
- require 'active_support/core_ext/module/delegation' # oh.. [add to gemspec?]
14
+ require 'active_support/core_ext/module/delegation' # oh..
15
15
 
16
16
  # monkeys out of the zoo!
17
17
  class Module
18
18
  def is *others; include *others end
19
19
  end
20
-
21
- # ... MySugar#x using mm
22
- # class Object
23
- # def method_missing name, *a, &block
24
- # if name =~ /^[^_]+_$/ && respond_to?(:name)
25
- # ........... map_{} ==> map &x {}
26
- # else super end
27
- # end
28
- # end
20
+ # ..
21
+ # to get method names I used:
22
+ # >> p methods = Enumerable.instance_methods.select {|x| Enumerable.instance_method(x).arity == 0 }
23
+ # no bang(!) versions
24
+ module Enumerable
25
+ methods = [:sort, :sort_by, :find_all, :select, :reject, :collect, :map, :flat_map,
26
+ :collect_concat, :partition, :group_by, :all?, :any?, :one?, :none?, :min,
27
+ :max, :minmax, :min_by, :max_by, :minmax_by, :take_while, :drop_while]
28
+ methods.each do |name|
29
+ define_method name[/^.*[^\?]/]+'_' do |&block|
30
+ send name, &x(&block)
31
+ end
32
+ end
33
+ end
data/spec/all_spec.rb CHANGED
@@ -3,11 +3,17 @@ require 'my-sugar'
3
3
  describe MySugar do
4
4
 
5
5
  specify 'light block' do
6
- ( [1,2,3].map &x{ to_s * 5 + ?! } ).should == %w[ 11111! 22222! 33333!]
6
+ ( [1,2,3].map &x{ to_s * 5 + ?! } ).should == %w[ 11111! 22222! 33333!]
7
7
  ( [1,2,3].all? &x{ is_a? Integer } ).should be_true
8
8
  ( [1,2,3].any? &x{ is_a? String } ).should be_false
9
9
  end
10
10
 
11
+ specify 'even more light block all? &x{...} ==> all_{...}' do
12
+ ( [1,2,3].map_{ to_s * 5 + ?! } ).should == %w[ 11111! 22222! 33333!]
13
+ ( [1,2,3].all_{ is_a? Integer } ).should be_true
14
+ ( [1,2,3].any_{ is_a? String } ).should be_false
15
+ end
16
+
11
17
  specify 'is == include' do
12
18
  module Testable; def test; 'here' end end
13
19
  class Any; is Testable end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my-sugar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: