methlab 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/methlab.rb +21 -1
- data/test/test_inline.rb +27 -0
- data/test/test_integrate.rb +2 -0
- metadata +4 -3
data/lib/methlab.rb
CHANGED
@@ -68,7 +68,7 @@
|
|
68
68
|
#
|
69
69
|
module MethLab
|
70
70
|
|
71
|
-
VERSION = "0.0.
|
71
|
+
VERSION = "0.0.9"
|
72
72
|
|
73
73
|
# Integrates MethLab into all namespaces. It does this by patching itself
|
74
74
|
# into ::main and Module.
|
@@ -350,6 +350,26 @@ module MethLab
|
|
350
350
|
end
|
351
351
|
end
|
352
352
|
|
353
|
+
#
|
354
|
+
# inline is useful to spec out several methods at once to yield similar values.
|
355
|
+
#
|
356
|
+
# Usage:
|
357
|
+
#
|
358
|
+
# class Foo
|
359
|
+
# inline(:one, :two, :three) { 1 }
|
360
|
+
# end
|
361
|
+
#
|
362
|
+
# f = Foo.new
|
363
|
+
# f.one # => 1
|
364
|
+
# f.two # => 1
|
365
|
+
# f.three # => 1
|
366
|
+
#
|
367
|
+
def inline(*method_names, &block)
|
368
|
+
method_names.each do |meth|
|
369
|
+
self.send(:define_method, meth, block)
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
353
373
|
if $METHLAB_AUTOINTEGRATE
|
354
374
|
integrate
|
355
375
|
end
|
data/test/test_inline.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'test-unit'
|
4
|
+
rescue LoadError
|
5
|
+
end
|
6
|
+
|
7
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
require 'methlab'
|
11
|
+
|
12
|
+
class InlineTest
|
13
|
+
inline(:foo) { nil }
|
14
|
+
inline(:bar, :baz, :quux) { 1 }
|
15
|
+
end
|
16
|
+
|
17
|
+
class TestInline < Test::Unit::TestCase
|
18
|
+
def test_01_inline_works
|
19
|
+
it = InlineTest.new
|
20
|
+
|
21
|
+
assert_equal(nil, it.foo)
|
22
|
+
|
23
|
+
[:bar, :baz, :quux].each do |meth|
|
24
|
+
assert_equal(1, it.send(meth))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/test/test_integrate.rb
CHANGED
@@ -21,10 +21,12 @@ class TestIntegrate < Test::Unit::TestCase
|
|
21
21
|
assert(module_methods.include?(:def_ordered) || module_methods.include?("def_ordered"))
|
22
22
|
assert(module_methods.include?(:build_named) || module_methods.include?("build_named"))
|
23
23
|
assert(module_methods.include?(:build_ordered) || module_methods.include?("build_ordered"))
|
24
|
+
assert(module_methods.include?(:inline) || module_methods.include?("inline"))
|
24
25
|
|
25
26
|
assert(main_methods.include?(:def_named) || main_methods.include?("def_named"))
|
26
27
|
assert(main_methods.include?(:def_ordered) || main_methods.include?("def_ordered"))
|
27
28
|
assert(main_methods.include?(:build_named) || main_methods.include?("build_named"))
|
28
29
|
assert(main_methods.include?(:build_ordered) || main_methods.include?("build_ordered"))
|
30
|
+
assert(main_methods.include?(:inline) || main_methods.include?("inline"))
|
29
31
|
end
|
30
32
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 9
|
9
|
+
version: 0.0.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Erik Hollensbe
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-26 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/methlab.rb
|
31
31
|
- test/test_checks.rb
|
32
32
|
- test/test_defaults.rb
|
33
|
+
- test/test_inline.rb
|
33
34
|
- test/test_integrate.rb
|
34
35
|
- Rakefile
|
35
36
|
- README
|