ruby_quirks 0.0.1
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 +15 -0
- data/.gitignore +34 -0
- data/.travis.yml +10 -0
- data/Gemfile +6 -0
- data/MIT-LICENSE +20 -0
- data/README.md +15 -0
- data/Rakefile +30 -0
- data/lib/ruby_quirks.rb +1 -0
- data/lib/ruby_quirks/hash.rb +1 -0
- data/lib/ruby_quirks/hash/enum_by_dup.rb +17 -0
- data/lib/ruby_quirks/version.rb +3 -0
- data/ruby_quirks.gemspec +26 -0
- data/spec/ruby_quirks/hash/enum_by_dup_spec.rb +39 -0
- data/spec/spec_helper.rb +15 -0
- metadata +102 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
YTA0MGEzMzc4YmViYmRiNTEwODIyZWQzNjEzMDViNTBlYzRmOTY0MQ==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
ZTIxMGU5MGQ5OGUyYzQ2MjRmMjA5ZDg3YzE4YWQ1NTFlYWZhOGRhOQ==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
ZTVhOTFkNTBlYjYxYTI5MjUwYmU4MjBmYjU0NGMwNzE2MDkxNmQ4OWY4MTM2
|
|
10
|
+
NDJkNTE0NDBmMWMzZmNhMWJhM2VkZmRlNWZhNjYwMDUzMjYwZDA2NjhkZWE0
|
|
11
|
+
OGE2YjRmYjk2NWY5NjBjMjNhMjc3MGJiM2I0Y2ZlODY4ODJiNTY=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
YTk3N2ZjYzkzZDlkZTIyNzRmZTA1YTY1Nzk1MGZjYWI5NDJkNmMzNzI3OGNk
|
|
14
|
+
ZWE2YjA1N2JkMDE4MDU2MjNiZTRiODYzYjE3ZjE0M2YyNWVhOTY1MjczZWUw
|
|
15
|
+
ZTg0NGU5MTY2YzhhYjZiNGE3ZjM1MjQwYTFiMWZmNmEzM2Q1YmI=
|
data/.gitignore
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/test/tmp/
|
|
9
|
+
/test/version_tmp/
|
|
10
|
+
/tmp/
|
|
11
|
+
|
|
12
|
+
## Specific to RubyMotion:
|
|
13
|
+
.dat*
|
|
14
|
+
.repl_history
|
|
15
|
+
build/
|
|
16
|
+
|
|
17
|
+
## Documentation cache and generated files:
|
|
18
|
+
/.yardoc/
|
|
19
|
+
/_yardoc/
|
|
20
|
+
/doc/
|
|
21
|
+
/rdoc/
|
|
22
|
+
|
|
23
|
+
## Environment normalisation:
|
|
24
|
+
/.bundle/
|
|
25
|
+
/lib/bundler/man/
|
|
26
|
+
|
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
29
|
+
Gemfile.lock
|
|
30
|
+
.ruby-version
|
|
31
|
+
.ruby-gemset
|
|
32
|
+
|
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
34
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2015 StreetEasy
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Ruby Quirks
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
[](https://travis-ci.org/StreetEasy/ruby_quirks) 
|
|
5
|
+
###### *For Ruby 1.9.3, 2.0.0, 2.1.0*
|
|
6
|
+
|
|
7
|
+
### Introduction
|
|
8
|
+
|
|
9
|
+
`ruby_quirks` is a gem which adds a collection of optional Ruby hotfixes and common idioms to accommodate for some of Ruby's quirky behaviors. See the list below to see what's offered.
|
|
10
|
+
|
|
11
|
+
### Hotfixes
|
|
12
|
+
|
|
13
|
+
#### Hash#reject and Hash#select returns Hash for subclasses of Hash
|
|
14
|
+
**Ruby versions: 2.2.0+**
|
|
15
|
+
**Description:
|
data/Rakefile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
require "bundler/gem_tasks"
|
|
3
|
+
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
RSpec::Core::RakeTask.new
|
|
6
|
+
task :default => :spec
|
|
7
|
+
task :test => :spec
|
|
8
|
+
|
|
9
|
+
namespace :doc do
|
|
10
|
+
begin
|
|
11
|
+
require 'yard'
|
|
12
|
+
rescue LoadError
|
|
13
|
+
# ignore
|
|
14
|
+
else
|
|
15
|
+
YARD::Rake::YardocTask.new do |task|
|
|
16
|
+
task.files = ['lib/**/*.rb']
|
|
17
|
+
task.options = [
|
|
18
|
+
'--protected',
|
|
19
|
+
'--output-dir', 'doc/yard',
|
|
20
|
+
'--tag', 'format:Supported formats',
|
|
21
|
+
'--markup', 'markdown',
|
|
22
|
+
]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
desc "Open an irb session preloaded with this library"
|
|
28
|
+
task :console do
|
|
29
|
+
sh "irb -rubygems -I lib -r ruby_quirks.rb"
|
|
30
|
+
end
|
data/lib/ruby_quirks.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'ruby_quirks/hash'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'ruby_quirks/hash/enum_by_dup'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# This module was created as a 'patch' for Hash behavior that changes in Ruby 2.2
|
|
2
|
+
# http://stackoverflow.com/questions/33638665/ruby-2-2-hashreject-returning-hash-for-inheriting-classes
|
|
3
|
+
# Hash#reject now always returns a Hash, rather than an instance of object that invoked #reject
|
|
4
|
+
# This new behavior breaks many classes that inherit from Hash
|
|
5
|
+
# Include this in classes that inherit from Hash to replicate the pre-2.2 Hash behavior
|
|
6
|
+
module RubyQuirks::Hash
|
|
7
|
+
module EnumByDup
|
|
8
|
+
def select(*args, &block)
|
|
9
|
+
return to_enum(:select) unless block_given?
|
|
10
|
+
dup.tap { |hash| hash.select!(*args, &block) }
|
|
11
|
+
end
|
|
12
|
+
def reject(*args, &block)
|
|
13
|
+
return to_enum(:reject) unless block_given?
|
|
14
|
+
dup.tap { |hash| hash.reject!(*args, &block) }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/ruby_quirks.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
$LOAD_PATH << File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "ruby_quirks/version"
|
|
4
|
+
|
|
5
|
+
# Describe your gem and declare its dependencies:
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = "ruby_quirks"
|
|
8
|
+
s.version = RubyQuirks::VERSION
|
|
9
|
+
s.authors = ["David Elner"]
|
|
10
|
+
s.email = ["david@streeteasy.com"]
|
|
11
|
+
s.homepage = "http://streeteasy.com"
|
|
12
|
+
s.summary = "Hotfixes and common idioms for the Ruby language."
|
|
13
|
+
s.description = "Hotfixes and common idioms for the Ruby language."
|
|
14
|
+
s.license = "MIT"
|
|
15
|
+
|
|
16
|
+
s.files = `git ls-files`.split("\n")
|
|
17
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
s.test_files = `git ls-files -- {spec,features,gemfiles}/*`.split("\n")
|
|
19
|
+
|
|
20
|
+
s.require_paths = ["lib"]
|
|
21
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
|
|
22
|
+
|
|
23
|
+
s.add_development_dependency "rake", "~> 10.0"
|
|
24
|
+
s.add_development_dependency "rspec", "~> 3.3"
|
|
25
|
+
s.add_development_dependency "yard", "~> 0.8.7.6"
|
|
26
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe RubyQuirks::Hash::EnumByDup do
|
|
4
|
+
let(:enum_by_dup_class) do
|
|
5
|
+
stub_const 'CustomHash', Class.new(Hash)
|
|
6
|
+
CustomHash.class_eval { include RubyQuirks::Hash::EnumByDup }
|
|
7
|
+
CustomHash
|
|
8
|
+
end
|
|
9
|
+
subject { enum_by_dup_class }
|
|
10
|
+
let(:enum_by_dup) { enum_by_dup_class.new }
|
|
11
|
+
|
|
12
|
+
# Populate the hash with test values
|
|
13
|
+
before(:each) do
|
|
14
|
+
enum_by_dup[1] = 'a'
|
|
15
|
+
enum_by_dup[2] = 'b'
|
|
16
|
+
enum_by_dup[3] = 'c'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "#select" do
|
|
20
|
+
context "with a block" do
|
|
21
|
+
subject { enum_by_dup.select { |k,v| k % 2 == 0 } }
|
|
22
|
+
it { expect(subject).to be_a_kind_of(enum_by_dup_class) }
|
|
23
|
+
end
|
|
24
|
+
context "without a block" do
|
|
25
|
+
subject { enum_by_dup.select }
|
|
26
|
+
it { expect(subject).to be_a_kind_of(Enumerator) }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
context "#reject" do
|
|
30
|
+
context "with a block" do
|
|
31
|
+
subject { enum_by_dup.reject { |k,v| k % 2 == 0 } }
|
|
32
|
+
it { expect(subject).to be_a_kind_of(enum_by_dup_class) }
|
|
33
|
+
end
|
|
34
|
+
context "without a block" do
|
|
35
|
+
subject { enum_by_dup.reject }
|
|
36
|
+
it { expect(subject).to be_a_kind_of(Enumerator) }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
|
|
6
|
+
require 'ruby_quirks'
|
|
7
|
+
|
|
8
|
+
RSpec.configure do |config|
|
|
9
|
+
config.expect_with :rspec do |expectations|
|
|
10
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
11
|
+
end
|
|
12
|
+
config.mock_with :rspec do |mocks|
|
|
13
|
+
mocks.verify_partial_doubles = true
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby_quirks
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- David Elner
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rake
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '10.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '10.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '3.3'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '3.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: yard
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.8.7.6
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.8.7.6
|
|
55
|
+
description: Hotfixes and common idioms for the Ruby language.
|
|
56
|
+
email:
|
|
57
|
+
- david@streeteasy.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- .travis.yml
|
|
64
|
+
- Gemfile
|
|
65
|
+
- MIT-LICENSE
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- lib/ruby_quirks.rb
|
|
69
|
+
- lib/ruby_quirks/hash.rb
|
|
70
|
+
- lib/ruby_quirks/hash/enum_by_dup.rb
|
|
71
|
+
- lib/ruby_quirks/version.rb
|
|
72
|
+
- ruby_quirks.gemspec
|
|
73
|
+
- spec/ruby_quirks/hash/enum_by_dup_spec.rb
|
|
74
|
+
- spec/spec_helper.rb
|
|
75
|
+
homepage: http://streeteasy.com
|
|
76
|
+
licenses:
|
|
77
|
+
- MIT
|
|
78
|
+
metadata: {}
|
|
79
|
+
post_install_message:
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ! '>='
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: 1.9.2
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ! '>='
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubyforge_project:
|
|
95
|
+
rubygems_version: 2.4.8
|
|
96
|
+
signing_key:
|
|
97
|
+
specification_version: 4
|
|
98
|
+
summary: Hotfixes and common idioms for the Ruby language.
|
|
99
|
+
test_files:
|
|
100
|
+
- spec/ruby_quirks/hash/enum_by_dup_spec.rb
|
|
101
|
+
- spec/spec_helper.rb
|
|
102
|
+
has_rdoc:
|