uberscore 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/lib/uberscore/version.rb +3 -0
- data/lib/uberscore.rb +35 -0
- data/spec/uberscore_spec.rb +19 -0
- data/uberscore.gemspec +23 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4822694e469030f33e07d66ddb926d5a6f2cbcdf
|
4
|
+
data.tar.gz: acf43d2893f4addbf867a752975c44d9acdfcfd1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 416976187c2332a1b626ca2f3dbd86931b37878f0822c8421b1e2f418c80b61f979dd5d78f7675a7c4444c106bf2b8c933b6b0eac6fca4bd00a305227ebd5d8e
|
7
|
+
data.tar.gz: cef66c9e18084f765495ca0b966c1ad2a82da0e41a42faa39232d7bb8c26830d51359ea0a5c2d5857f4af9051cf03386bda4a015e94832c1a6e58a5092c28c6c
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Volodymyr Shatsky
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Uberscore
|
2
|
+
|
3
|
+
Born to make your Ruby blocks more concise.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
# Chain method calls.
|
7
|
+
%w[0x 0d ea].map { |element| element.hex.divmod(13)[1] == 0 } # Without Uberscore
|
8
|
+
%w[0x 0d ea].map(&_.hex.divmod(13)[1] == 0) # With Uberscore
|
9
|
+
|
10
|
+
# Use class methods.
|
11
|
+
[Array, Hash].map { |a_class| a_class.new(4) }
|
12
|
+
[Array, Hash].map(&_.new(4))
|
13
|
+
|
14
|
+
# Nest.
|
15
|
+
[[2, 3]].map { |array| array.map { |element| element * 2 } }
|
16
|
+
[[2, 3]].map(&_.map(&_ * 2))
|
17
|
+
|
18
|
+
# Subscript.
|
19
|
+
[{ name: "foo" }, { name: "bar" }].map { |hash| hash[:name] }
|
20
|
+
[{ name: "foo" }, { name: "bar" }].map(&_[:name])
|
21
|
+
```
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'uberscore'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install uberscore
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
MIT
|
data/Rakefile
ADDED
data/lib/uberscore.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "uberscore/version"
|
2
|
+
|
3
|
+
module Uberscore
|
4
|
+
class Context < BasicObject
|
5
|
+
class << self
|
6
|
+
alias_method :__new_uberscore_context__, :new
|
7
|
+
undef_method :new
|
8
|
+
end
|
9
|
+
|
10
|
+
undef_method :!
|
11
|
+
undef_method :!=
|
12
|
+
undef_method :==
|
13
|
+
undef_method :__id__
|
14
|
+
undef_method :__send__
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@call_chain = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(name, *args, &block)
|
21
|
+
@call_chain << [name, args, block]
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_proc
|
26
|
+
->(object) do
|
27
|
+
@call_chain.reduce(object) do |current, (name, args, block)|
|
28
|
+
current.public_send(name, *args, &block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Kernel.send(:define_method, :_) { Context.__new_uberscore_context__ }
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "../lib/uberscore"
|
2
|
+
|
3
|
+
describe Uberscore do
|
4
|
+
it "chains method calls" do
|
5
|
+
expect(%w[0x 0d ea].map(&_.hex.divmod(13)[1] == 0)).to eq(%w[0x 0d ea].map { |element| element.hex.divmod(13)[1] == 0 })
|
6
|
+
end
|
7
|
+
|
8
|
+
it "can call ::new" do
|
9
|
+
expect([Array, Hash].map(&_.new(4))).to eq([Array, Hash].map { |a_class| a_class.new(4) })
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can be nested" do
|
13
|
+
expect([[2, 3]].map(&_.map(&_ * 2))).to eq([[2, 3]].map { |array| array.map { |element| element * 2 } })
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can subscript" do
|
17
|
+
expect([{ name: "foo" }, { name: "bar" }].map(&_[:name])).to eq([{ name: "foo" }, { name: "bar" }].map { |hash| hash[:name] })
|
18
|
+
end
|
19
|
+
end
|
data/uberscore.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'uberscore/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "uberscore"
|
8
|
+
spec.version = Uberscore::VERSION
|
9
|
+
spec.authors = %w(Ox0dea shock_one)
|
10
|
+
spec.summary = %q{A gem that makes your Ruby blocks more concise.}
|
11
|
+
spec.description = %q{A gem that makes your Ruby blocks more concise.}
|
12
|
+
spec.homepage = "https://github.com/shockone/uberscore"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uberscore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ox0dea
|
8
|
+
- shock_one
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.6'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.6'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: A gem that makes your Ruby blocks more concise.
|
57
|
+
email:
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/uberscore.rb
|
68
|
+
- lib/uberscore/version.rb
|
69
|
+
- spec/uberscore_spec.rb
|
70
|
+
- uberscore.gemspec
|
71
|
+
homepage: https://github.com/shockone/uberscore
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: A gem that makes your Ruby blocks more concise.
|
95
|
+
test_files:
|
96
|
+
- spec/uberscore_spec.rb
|