kernel-let 1.0.4
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.
- checksums.yaml +7 -0
- data/LICENSE.txt +23 -0
- data/README.org +55 -0
- data/kernel-let.gemspec +14 -0
- data/lib/kernel/let.rb +16 -0
- data/lib/kernel/let/version.rb +5 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1cf99de015c5679153f6725a4277cc6ce0455783
|
4
|
+
data.tar.gz: 9cf3e70bae6b4ccb115b034956f15af9a83cfdd9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21683610d21e17626e154b0a798e604ab3b6c40dd3dbe4b745f66191cb38792878c250c9f337dcd61cfaa108fd62c2689998e293adc5b3aefa0ca33fd921f81f
|
7
|
+
data.tar.gz: bf950f7a68fd8eb19801ba2b82f0f49f5515074f201c6e5451a2ca77e29fa817a723389956d42edea3b874aa8a21833255a32d76336ce67448f8089de1d74e15
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
The MIT License (MIT)
|
3
|
+
|
4
|
+
Copyright © 2011 Arnau Sanchez
|
5
|
+
Copyright © 2016 Chris Olstrom <chris@olstrom.com>
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
of this software and associated documentation files (the “Software”), to deal
|
9
|
+
in the Software without restriction, including without limitation the rights
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
12
|
+
furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
15
|
+
all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
THE SOFTWARE.
|
data/README.org
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#+TITLE: Kernel#let
|
2
|
+
#+LATEX: \pagebreak
|
3
|
+
|
4
|
+
* Overview
|
5
|
+
|
6
|
+
=kernel-let= is a single-method gem that monkey patches a clean =let= method
|
7
|
+
onto =Kernel=, providing Scheme-style variable binding in Ruby.
|
8
|
+
|
9
|
+
* Why does this exist?
|
10
|
+
|
11
|
+
Monkey patching is a good thing, when used responsibly. Using something
|
12
|
+
responsibly is easier when we choose when to use it. Having this method as a
|
13
|
+
standalone gem makes that choice easier.
|
14
|
+
|
15
|
+
* Installation
|
16
|
+
|
17
|
+
#+BEGIN_SRC shell
|
18
|
+
gem install kernel-let
|
19
|
+
#+END_SRC
|
20
|
+
|
21
|
+
* Usage
|
22
|
+
|
23
|
+
First, we need to require it.
|
24
|
+
|
25
|
+
#+BEGIN_SRC ruby
|
26
|
+
require 'kernel/let'
|
27
|
+
#+END_SRC
|
28
|
+
|
29
|
+
~let~ takes any number of names and values, and a block. Within the block, the
|
30
|
+
values are bound to the given name.
|
31
|
+
|
32
|
+
#+BEGIN_SRC ruby
|
33
|
+
let(foo: 'bar', bar: 'baz') { foo + bar } # => "barbaz"
|
34
|
+
|
35
|
+
let foo: 'bar', bar: 'baz' do
|
36
|
+
foo + bar
|
37
|
+
end # => "barbaz"
|
38
|
+
#+END_SRC
|
39
|
+
|
40
|
+
If no block was given, ~let~ will return a Proc which will evaluate a block in
|
41
|
+
the context it was created with.
|
42
|
+
|
43
|
+
#+BEGIN_SRC ruby
|
44
|
+
context = let foo: 'bar', bar: 'baz'
|
45
|
+
context.call { foo } # => "barbaz"
|
46
|
+
context.() { foo } # => "barbaz"
|
47
|
+
#+END_SRC
|
48
|
+
|
49
|
+
* License
|
50
|
+
|
51
|
+
~kernel-let~ is available under the [[https://tldrlegal.com/license/mit-license][MIT License]]. See ~LICENSE.txt~ for the full text.
|
52
|
+
|
53
|
+
* Contributors
|
54
|
+
- Arnau Sanchez
|
55
|
+
- [[https://colstrom.github.io/][Chris Olstrom]] | [[mailto:chris@olstrom.com][e-mail]] | [[https://twitter.com/ChrisOlstrom][Twitter]]
|
data/kernel-let.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = 'kernel-let'
|
3
|
+
gem.version = `git describe --tags --abbrev=0`.chomp
|
4
|
+
gem.licenses = 'MIT'
|
5
|
+
gem.authors = ['Chris Olstrom', 'Arnau Sanchez']
|
6
|
+
gem.email = 'chris@olstrom.com'
|
7
|
+
gem.homepage = 'https://github.com/colstrom/kernel-let'
|
8
|
+
gem.summary = 'Monkey patch adding Kernel#let for Scheme-style variable bindings.'
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split("\n")
|
11
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
12
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
13
|
+
gem.require_paths = ['lib']
|
14
|
+
end
|
data/lib/kernel/let.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'let/version'
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
def let(**context, &block)
|
5
|
+
if block_given?
|
6
|
+
let(context).call(&block)
|
7
|
+
else
|
8
|
+
lambda do |&action|
|
9
|
+
Struct
|
10
|
+
.new(*context.keys)
|
11
|
+
.new(*context.values)
|
12
|
+
.instance_eval(&action)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kernel-let
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Olstrom
|
8
|
+
- Arnau Sanchez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-10-03 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: chris@olstrom.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE.txt
|
21
|
+
- README.org
|
22
|
+
- kernel-let.gemspec
|
23
|
+
- lib/kernel/let.rb
|
24
|
+
- lib/kernel/let/version.rb
|
25
|
+
homepage: https://github.com/colstrom/kernel-let
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.6.7
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Monkey patch adding Kernel#let for Scheme-style variable bindings.
|
49
|
+
test_files: []
|