gensym 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a5b343c916fe90ad217ad946e3fad385a045175
4
+ data.tar.gz: 654ad011e02999adfdb3babd26282df2a5a10ffe
5
+ SHA512:
6
+ metadata.gz: e5021fdfb8207133f0df66e7c85bb83bb3822ae3948cc95d29a2a8df0437549078bd70c21ed8ab28753310aa3a19eb2b077cb73cd121ee887ba11d2efdfca983
7
+ data.tar.gz: 3073a9cd4342642766e0cad95edcff9688ee556d1ac4147347e0c2712def0a9cfa1c54277aeb8a86d1355506dc58bd7f69f87911d55db531378393344b6cd2a4
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gensym.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ ## Gensym [![Build Status](https://secure.travis-ci.org/hrs/gensym.png?branch=master&.png)](http://travis-ci.org/hrs/gensym) [![Code Climate](https://codeclimate.com/github/hrs/gensym/badges/gpa.svg)](https://codeclimate.com/github/hrs/gensym)
2
+
3
+ Generate new, unbound variable names in your Ruby program. An homage to Lisp's
4
+ `gensym` macro.
5
+
6
+ Handy for the kind of metaprogramming you really shouldn't be doing.
7
+
8
+ ## Usage
9
+
10
+ Instantiate a `Gensym` object by passing in a [`Binding`][]. You'll probably
11
+ want the binding of the current scope returned by `Kernel#binding`. Generate a
12
+ new symbol by calling `generate`:
13
+
14
+ ```ruby
15
+ Gensym.new(binding).generate # => :gensym_OMUYsTEIbvjGwqhQgifkJNaByAHzxc
16
+ ```
17
+
18
+ [`Binding`]: http://ruby-doc.org/core-2.4.1/Binding.html
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem "gensym"
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install gensym
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
39
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
40
+ prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To
43
+ release a new version, update the version number in `version.rb`, and then run
44
+ `bundle exec rake release`, which will create a git tag for the version, push
45
+ git commits and tags, and push the `.gem` file to [rubygems.org][].
46
+
47
+ [rubygems.org]: https://rubygems.org
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gensym"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/gensym.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gensym"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gensym"
8
+ spec.version = Gensym::VERSION
9
+ spec.authors = ["Harry R. Schwartz"]
10
+ spec.email = ["hello@harryrschwartz.com"]
11
+
12
+ spec.summary = "Generate an unbound symbol."
13
+ spec.homepage = "https://github.com/hrs/gensym"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.14"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
data/lib/gensym.rb ADDED
@@ -0,0 +1,35 @@
1
+ class Gensym
2
+ ALPHABET = ("A".."Z").to_a + ("a".."z").to_a
3
+ PREFIX = "gensym_"
4
+ SUFFIX_LENGTH = 30
5
+ VERSION = "0.1.0"
6
+
7
+ def initialize(callsite_binding, generator = nil)
8
+ @callsite_binding = callsite_binding
9
+ @symbol_generator = generator || new_symbol_generator
10
+ end
11
+
12
+ def generate
13
+ symbol_generator.detect { |symbol| !bound?(symbol) }
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :callsite_binding, :symbol_generator
19
+
20
+ def bound?(symbol)
21
+ callsite_binding.local_variable_defined?(symbol)
22
+ end
23
+
24
+ def new_symbol_generator
25
+ Enumerator.new do |yielder|
26
+ loop do
27
+ yielder.yield(random_symbol)
28
+ end
29
+ end
30
+ end
31
+
32
+ def random_symbol
33
+ (PREFIX + ALPHABET.sample(SUFFIX_LENGTH).join).to_sym
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gensym
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Harry R. Schwartz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - hello@harryrschwartz.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - gensym.gemspec
71
+ - lib/gensym.rb
72
+ homepage: https://github.com/hrs/gensym
73
+ licenses: []
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.6.8
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Generate an unbound symbol.
95
+ test_files: []