newk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9990a3e1c2fc65436fb98cd014ca6185b03cf3ee
4
+ data.tar.gz: b643c7a02530341c43d86ddd8c82e2bd311475ff
5
+ SHA512:
6
+ metadata.gz: 1a45b60c3df6c531ed032bc90b35aefdec1bcb640570dc35c10985d65d4e3841e20244a504e8191808cb28d81d830c4092fa382aa81b6e6930b6909b153ecc13
7
+ data.tar.gz: 35c2b75117366e91dc8ab234e3d6b8d8197afd2095ae96253a2b453957de436904971b8d035bc055b63be5c0357fbf4e0d6e73c79d40cab21e7a64a7fec98319
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in newk.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Justin Campbell
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.
@@ -0,0 +1,46 @@
1
+ # Newk
2
+
3
+ Remove the need for `.new` in Ruby. You should probably never use this.
4
+
5
+ ## Newk a class
6
+
7
+ ```rb
8
+ class Animal
9
+ def initialize(type)
10
+ @type = type
11
+ end
12
+ end
13
+
14
+ require 'newk'
15
+ Newk.newk Animal
16
+
17
+ Animal(:cat) # => #<Animal:0x007ff0992b3ea0 @type=:cat>
18
+ ```
19
+
20
+ ## Newk everything
21
+
22
+ ```rb
23
+ class Animal
24
+ def initialize(type)
25
+ @type = type
26
+ end
27
+ end
28
+
29
+ require 'newk/everything'
30
+
31
+ Animal(:cat) # => #<Animal:0x007ff0992b3ea0 @type=:cat>
32
+ ```
33
+
34
+ ## ...even in the future
35
+
36
+ ```rb
37
+ require 'newk/everything'
38
+
39
+ class Animal
40
+ def initialize(type)
41
+ @type = type
42
+ end
43
+ end
44
+
45
+ Animal(:cat) # => #<Animal:0x007ff0992b3ea0 @type=:cat>
46
+ ```
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task default: [:test]
5
+
6
+ Rake::TestTask.new do |test|
7
+ test.test_files = FileList['spec/*_spec.rb']
8
+ test.verbose = true
9
+ test.warning = true
10
+ end
@@ -0,0 +1,23 @@
1
+ require "newk/version"
2
+
3
+ module Newk
4
+ def self.included(base)
5
+ newk base
6
+ end
7
+
8
+ def self.newk(klass)
9
+ class_name = klass.name
10
+
11
+ return unless class_name
12
+
13
+ method_name = class_name.to_sym
14
+
15
+ return if \
16
+ Kernel.private_method_defined?(method_name) ||
17
+ Kernel.public_method_defined?(method_name)
18
+
19
+ Kernel.send :define_method, method_name do |*args|
20
+ klass.new(*args)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'newk'
2
+
3
+ ObjectSpace.each_object(Class) do |klass|
4
+ Newk.newk klass
5
+ end
6
+
7
+ class Object
8
+ def self.inherited(klass)
9
+ Newk.newk klass
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Newk
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'newk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "newk"
8
+ spec.version = Newk::VERSION
9
+ spec.authors = ["Justin Campbell"]
10
+ spec.email = ["justin@justincampbell.me"]
11
+ spec.summary = "Remove the need for `.new` in Ruby"
12
+ spec.description = "Remove the need for `.new` in Ruby. You should probably never use this."
13
+ spec.homepage = "https://github.com/justincampbell/newk"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest"
24
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'spec_helper'
2
+
3
+ class Klass
4
+ def worked?; true; end
5
+ end
6
+
7
+ describe Newk do
8
+ before { cleanup_methods }
9
+
10
+ it "defines the method when newk-ing" do
11
+ Newk.newk Klass
12
+ assert Klass().worked?
13
+ end
14
+
15
+ it "defines the method if included" do
16
+ Klass.send :include, Newk
17
+ assert Klass().worked?
18
+ end
19
+
20
+ describe 'everything' do
21
+ before { require 'newk/everything' }
22
+
23
+ it "defines methods for existing classes" do
24
+ assert Klass().worked?
25
+ end
26
+
27
+ it "defines methods for future classes" do
28
+ class Future; def worked?; true; end; end
29
+ assert Future().worked?
30
+ end
31
+
32
+ it "doesn't clobber existing methods" do
33
+ assert_equal [], Array(nil)
34
+ assert_equal [:foo], Array(:foo)
35
+ end
36
+ end
37
+ end
38
+
39
+ def cleanup_methods
40
+ [:Future, :Klass].each do |klass|
41
+ Kernel.send :undef, klass rescue nil
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ gem 'minitest'
2
+ require 'minitest/autorun'
3
+
4
+ lib = File.expand_path('../../lib', __FILE__)
5
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
6
+
7
+ require 'newk'
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: newk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Campbell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-04 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Remove the need for `.new` in Ruby. You should probably never use this.
56
+ email:
57
+ - justin@justincampbell.me
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/newk.rb
68
+ - lib/newk/everything.rb
69
+ - lib/newk/version.rb
70
+ - newk.gemspec
71
+ - spec/newk_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: https://github.com/justincampbell/newk
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.5
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Remove the need for `.new` in Ruby
97
+ test_files:
98
+ - spec/newk_spec.rb
99
+ - spec/spec_helper.rb
100
+ has_rdoc: