double 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,17 +1,5 @@
1
1
  *.gem
2
2
  *.rbc
3
3
  .bundle
4
- .config
5
- .yardoc
6
4
  Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
5
  pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.3
4
+ - jruby-18mode
5
+ - jruby-19mode
6
+ - rbx-18mode
7
+ - rbx-19mode
data/README.md CHANGED
@@ -1,31 +1,25 @@
1
1
  # Double
2
2
 
3
- Something can be [familiar, yet foreign][uncanny] at the same time.
3
+ [![travis][status]][travis]
4
4
 
5
- ## Installation
5
+ ![repliee][repliee]
6
6
 
7
- Add this line to your application's **Gemfile**:
7
+ ## Description
8
8
 
9
- ```ruby
10
- gem 'double'
11
- ```
9
+ Something can be [familiar, yet foreign at once][uncanny]—particularly when metaprogramming.
12
10
 
13
- Or install it yourself as:
14
-
15
- ```sh
16
- $ gem install double
17
- ```
11
+ **Double** allows you to use a constant even before it is defined.
18
12
 
19
13
  ## Usage
20
14
 
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
15
+ ```ruby
16
+ class Foo
17
+ extend Double
18
+ Bar
19
+ end
20
+ ```
30
21
 
22
+ [status]: https://secure.travis-ci.org/hakanensari/double.png
23
+ [travis]: http://travis-ci.org/hakanensari/double
31
24
  [uncanny]: http://www-rohan.sdsu.edu/~amtower/uncanny.html
25
+ [repliee]: http://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Repliee_Q2.jpg/344px-Repliee_Q2.jpg
@@ -5,8 +5,8 @@ Gem::Specification.new do |gem|
5
5
  gem.authors = ['Hakan Ensari']
6
6
  gem.email = ['hakan.ensari@papercavalier.com']
7
7
  gem.description = %q{Familiar, yet foreign}
8
- gem.summary = %q{Familiar, yet foreign}
9
- gem.homepage = "https://github.com/hakanensari/double"
8
+ gem.summary = %q{Allows you to use a constant even before it is defined.}
9
+ gem.homepage = 'https://github.com/hakanensari/double'
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -15,5 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ['lib']
16
16
  gem.version = Double::VERSION
17
17
 
18
- gem.add_development_dependency 'minitest', '~> 3.0'
18
+ gem.add_development_dependency 'rake'
19
19
  end
@@ -1 +1,39 @@
1
- require 'double/version'
1
+ # Based on http://git.io/D7oevQ
2
+ require 'forwardable'
3
+
4
+ unless defined? BasicObject
5
+ class BasicObject
6
+ instance_methods.each do |mth|
7
+ undef_method mth unless mth =~ /__/
8
+ end
9
+ end
10
+ end
11
+
12
+ module Double
13
+ class Klass < BasicObject
14
+ extend ::Forwardable
15
+
16
+ def initialize(name)
17
+ @name = name
18
+ end
19
+
20
+ def _
21
+ @_ ||= ::Kernel.const_get @name
22
+ end
23
+
24
+ def method_missing(mth, *args, &blk)
25
+ if _.respond_to? mth
26
+ (class << self; self; end).instance_eval do
27
+ def_delegator :@_, mth
28
+ end
29
+ @_.send mth, *args, &blk
30
+ else
31
+ super
32
+ end
33
+ end
34
+ end
35
+
36
+ def const_missing(name)
37
+ Klass.new name
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
- class Double
2
- VERSION = '0.0.1'
1
+ module Double
2
+ VERSION = '0.1.0'
3
3
  end
@@ -1,6 +1,40 @@
1
- require 'helper'
1
+ require 'test/unit'
2
2
  require 'double'
3
3
 
4
- describe Double do
5
- it 'pends'
4
+ module Foo
5
+ class << self
6
+ attr_accessor :double
7
+ end
8
+ end
9
+
10
+ class TestDouble < Test::Unit::TestCase
11
+ def test_lazy_evaluate
12
+ assert_raise NameError do
13
+ Foo.class_eval 'self.double = Bar'
14
+ end
15
+
16
+ Foo.extend Double
17
+ Foo.class_eval 'self.double = Bar'
18
+ assert_raise NameError do
19
+ Foo.double.baz
20
+ end
21
+
22
+ Kernel.const_set :Bar, Module.new
23
+ assert_raise NoMethodError do
24
+ Bar.baz
25
+ end
26
+ assert_raise NoMethodError do
27
+ Foo.double.baz
28
+ end
29
+
30
+ Bar.class_eval { def self.baz; 1; end }
31
+ assert_equal 1, Bar.baz
32
+ assert_equal 1, Foo.double.baz
33
+ end
34
+
35
+ def test_memoize
36
+ Double::Klass.class_eval { def method_missing(*args); 2; end }
37
+ assert_equal 1, Foo.double.baz
38
+ assert_equal 2, Foo.double.qux
39
+ end
6
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: double
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-15 00:00:00.000000000 Z
12
+ date: 2012-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: minitest
15
+ name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '3.0'
21
+ version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '3.0'
29
+ version: '0'
30
30
  description: Familiar, yet foreign
31
31
  email:
32
32
  - hakan.ensari@papercavalier.com
@@ -35,6 +35,7 @@ extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - .gitignore
38
+ - .travis.yml
38
39
  - Gemfile
39
40
  - LICENSE
40
41
  - README.md
@@ -42,7 +43,6 @@ files:
42
43
  - double.gemspec
43
44
  - lib/double.rb
44
45
  - lib/double/version.rb
45
- - test/helper.rb
46
46
  - test/test_double.rb
47
47
  homepage: https://github.com/hakanensari/double
48
48
  licenses: []
@@ -67,7 +67,7 @@ rubyforge_project:
67
67
  rubygems_version: 1.8.23
68
68
  signing_key:
69
69
  specification_version: 3
70
- summary: Familiar, yet foreign
70
+ summary: Allows you to use a constant even before it is defined.
71
71
  test_files:
72
- - test/helper.rb
73
72
  - test/test_double.rb
73
+ has_rdoc:
@@ -1,3 +0,0 @@
1
- require 'minitest/unit'
2
- require 'minitest/pride'
3
- require 'minitest/autorun'