slam 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rst +28 -0
  2. data/lib/slam.rb +34 -0
  3. data/slam.gemspec +13 -0
  4. data/spec/slam_spec.rb +38 -0
  5. metadata +66 -0
data/README.rst ADDED
@@ -0,0 +1,28 @@
1
+ Slam: Symbol-LAMbda
2
+ ================================================================================
3
+
4
+ Slam provides an symbol-hack.
5
+
6
+ .. code:: ruby
7
+
8
+ L = Slam::Dunk.new
9
+
10
+ # [:foo, :bar, :baz].map{|s| s.to_s }.map{|s| s.upcase }
11
+ # [:foo, :bar, :baz].map(&:to_s).map(&:upcase)
12
+
13
+ [:foo, :bar, :baz].map &L.to_s . upcase
14
+
15
+ # [:foo, :hoge, :bar, :fuga].select{|s| s.to_s.length > 3} # => [:hoge, :fuga]
16
+
17
+ [:foo, :hoge, :bar, :fuga].select &L.to_s . length > 3
18
+
19
+ # (1..5).map { |x| x ** 2 }
20
+
21
+ (1..5).map &L ** 2 # => [1, 4, 9, 16, 25]
22
+
23
+ Installation
24
+ --------------------------------------------------------------------------------
25
+
26
+ .. code:: sh
27
+
28
+ gem install slam
data/lib/slam.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Slam
2
+
3
+ class Base < BasicObject
4
+
5
+ private *instance_methods
6
+ end
7
+
8
+ class Dunk < Base
9
+
10
+ def method_missing(name, *args, &block)
11
+ Compose.new(name, *args, &block)
12
+ end
13
+ end
14
+
15
+ class Compose < Base
16
+
17
+ def initialize(callable, *args, &block)
18
+ @callable = callable.to_proc
19
+ @args = args
20
+ @block = block
21
+ end
22
+
23
+ def method_missing(name, *args, &block)
24
+ f = to_proc
25
+ g = Compose.new(name, *args, &block).to_proc
26
+ h = ->(*args, &block) { g.(f.(*args, &block)) }
27
+ Compose.new(h)
28
+ end
29
+
30
+ def to_proc
31
+ ->(*args, &block) { @callable.(*args, *@args, &(block||@block)) }
32
+ end
33
+ end
34
+ end
data/slam.gemspec ADDED
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "slam"
3
+ s.version = File.read("VERSION")
4
+ s.authors = ["pasberth"]
5
+ s.description = %{Symbol-LAMbda hacks}
6
+ s.summary = %q{experimental release}
7
+ s.email = "pasberth@gmail.com"
8
+ s.homepage = "http://github.com/pasberth/slam"
9
+ s.require_paths = ["lib"]
10
+ s.files = `git ls-files`.split("\n")
11
+ s.test_files = `git ls-files -- spec/*`.split("\n")
12
+ s.add_development_dependency "rspec"
13
+ end
data/spec/slam_spec.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'slam'
3
+
4
+ describe Slam::Dunk do
5
+
6
+ let(:l) { described_class.new }
7
+
8
+ example do
9
+ [:foo, :bar, :baz].map(&l.to_s . upcase).
10
+ should == ["FOO", "BAR", "BAZ"]
11
+ end
12
+
13
+ example do
14
+ [:foo, :hoge, :bar, :fuga].select(&l.to_s . length > 3).
15
+ should == [:hoge, :fuga]
16
+ end
17
+
18
+ example do
19
+ qstr = "hoge=fuga&foo=bar"
20
+ Hash[qstr.split(?&).map &l.split(?=)].
21
+ should == {"hoge"=>"fuga", "foo"=>"bar"}
22
+ end
23
+
24
+ example do
25
+ (1..5).map(&l ** 2).
26
+ should == [1, 4, 9, 16, 25]
27
+ end
28
+
29
+ example do
30
+ %w[c++ lisp].map(&(l + "er").upcase).
31
+ should == ["C++ER", "LISPER"]
32
+ end
33
+
34
+ example do
35
+ %w[c++ lisp].map(&l.upcase + "er").
36
+ should == ["C++er", "LISPer"]
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - pasberth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Symbol-LAMbda hacks
31
+ email: pasberth@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - README.rst
37
+ - lib/slam.rb
38
+ - slam.gemspec
39
+ - spec/slam_spec.rb
40
+ homepage: http://github.com/pasberth/slam
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.24
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: experimental release
64
+ test_files:
65
+ - spec/slam_spec.rb
66
+ has_rdoc: