fuby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/fuby.gemspec +21 -0
- data/lib/fuby.rb +1 -0
- data/lib/fuby/abbreviation.rb +20 -0
- data/lib/fuby/alias_method.rb +13 -0
- data/lib/fuby/all.rb +11 -0
- data/lib/fuby/and.rb +9 -0
- data/lib/fuby/any.rb +11 -0
- data/lib/fuby/attributes.rb +17 -0
- data/lib/fuby/bind.rb +21 -0
- data/lib/fuby/class_attributes.rb +39 -0
- data/lib/fuby/deep.rb +1 -0
- data/lib/fuby/deep_each.rb +14 -0
- data/lib/fuby/define_instance_method.rb +18 -0
- data/lib/fuby/define_missing_method.rb +36 -0
- data/lib/fuby/define_object_method.rb +18 -0
- data/lib/fuby/define_tok.rb +11 -0
- data/lib/fuby/descendants.rb +15 -0
- data/lib/fuby/dimension.rb +23 -0
- data/lib/fuby/drop.rb +20 -0
- data/lib/fuby/drop_until.rb +18 -0
- data/lib/fuby/drop_while.rb +15 -0
- data/lib/fuby/each.rb +2 -0
- data/lib/fuby/each_with_index_or_key.rb +19 -0
- data/lib/fuby/eql.rb +1 -0
- data/lib/fuby/eql_componentwise.rb +13 -0
- data/lib/fuby/equivalence.rb +13 -0
- data/lib/fuby/eval.rb +54 -0
- data/lib/fuby/extend.rb +13 -0
- data/lib/fuby/format.rb +9 -0
- data/lib/fuby/include.rb +13 -0
- data/lib/fuby/index_or_key.rb +19 -0
- data/lib/fuby/instance_attributes.rb +39 -0
- data/lib/fuby/intercept.rb +27 -0
- data/lib/fuby/invert.rb +16 -0
- data/lib/fuby/longest_common.rb +16 -0
- data/lib/fuby/matches.rb +11 -0
- data/lib/fuby/matches_componentwise.rb +11 -0
- data/lib/fuby/matches_part_of.rb +16 -0
- data/lib/fuby/matches_prefix_of.rb +11 -0
- data/lib/fuby/matches_suffix_of.rb +13 -0
- data/lib/fuby/member.rb +11 -0
- data/lib/fuby/merge.rb +20 -0
- data/lib/fuby/merge_css.rb +32 -0
- data/lib/fuby/method_added_as.rb +1 -0
- data/lib/fuby/method_added_as_binary_operator.rb +16 -0
- data/lib/fuby/method_added_as_filter.rb +19 -0
- data/lib/fuby/new.rb +16 -0
- data/lib/fuby/not.rb +25 -0
- data/lib/fuby/opposite.rb +29 -0
- data/lib/fuby/or.rb +9 -0
- data/lib/fuby/otherwise.rb +18 -0
- data/lib/fuby/part_of.rb +16 -0
- data/lib/fuby/plus.rb +10 -0
- data/lib/fuby/pop.rb +11 -0
- data/lib/fuby/pop_if.rb +15 -0
- data/lib/fuby/pop_options.rb +15 -0
- data/lib/fuby/pop_unless.rb +11 -0
- data/lib/fuby/pop_until.rb +11 -0
- data/lib/fuby/pop_while.rb +11 -0
- data/lib/fuby/prefix_of.rb +14 -0
- data/lib/fuby/prefixes.rb +11 -0
- data/lib/fuby/prepend.rb +11 -0
- data/lib/fuby/private.rb +11 -0
- data/lib/fuby/protected.rb +11 -0
- data/lib/fuby/public.rb +11 -0
- data/lib/fuby/push.rb +1 -0
- data/lib/fuby/push_options.rb +9 -0
- data/lib/fuby/random.rb +31 -0
- data/lib/fuby/self_and_descendants.rb +15 -0
- data/lib/fuby/shift.rb +11 -0
- data/lib/fuby/shift_if.rb +12 -0
- data/lib/fuby/shift_options.rb +11 -0
- data/lib/fuby/shift_unless.rb +12 -0
- data/lib/fuby/shift_until.rb +12 -0
- data/lib/fuby/shift_while.rb +16 -0
- data/lib/fuby/splat.rb +11 -0
- data/lib/fuby/strip.rb +24 -0
- data/lib/fuby/subclass.rb +22 -0
- data/lib/fuby/submodule.rb +22 -0
- data/lib/fuby/suffix_of.rb +19 -0
- data/lib/fuby/suffixes.rb +11 -0
- data/lib/fuby/take.rb +20 -0
- data/lib/fuby/take_until.rb +17 -0
- data/lib/fuby/take_while.rb +14 -0
- data/lib/fuby/tap.rb +28 -0
- data/lib/fuby/to.rb +1 -0
- data/lib/fuby/to_boolean.rb +32 -0
- data/lib/fuby/to_camel_case.rb +32 -0
- data/lib/fuby/to_case.rb +1 -0
- data/lib/fuby/to_components.rb +33 -0
- data/lib/fuby/to_dash_case.rb +28 -0
- data/lib/fuby/to_hash.rb +25 -0
- data/lib/fuby/to_pred.rb +7 -0
- data/lib/fuby/to_proc.rb +45 -0
- data/lib/fuby/to_regexp.rb +38 -0
- data/lib/fuby/to_snake_case.rb +28 -0
- data/lib/fuby/to_tok.rb +27 -0
- data/lib/fuby/tok.rb +2 -0
- data/lib/fuby/tok_arity.rb +18 -0
- data/lib/fuby/tok_direction.rb +16 -0
- data/lib/fuby/tok_parity.rb +11 -0
- data/lib/fuby/tok_side.rb +11 -0
- data/lib/fuby/try.rb +73 -0
- data/lib/fuby/try_each.rb +25 -0
- data/lib/fuby/try_eval.rb +19 -0
- data/lib/fuby/try_exec.rb +15 -0
- data/lib/fuby/unabbreviation.rb +17 -0
- data/lib/fuby/unshift.rb +1 -0
- data/lib/fuby/unshift_options.rb +11 -0
- data/lib/fuby/uuid.rb +28 -0
- data/test/fuby/abbreviation.rb +25 -0
- data/test/fuby/alias_method.rb +29 -0
- data/test/fuby/all.rb +15 -0
- data/test/fuby/and.rb +14 -0
- data/test/fuby/any.rb +15 -0
- data/test/fuby/attributes.rb +0 -0
- data/test/fuby/bind.rb +17 -0
- data/test/fuby/class_attributes.rb +0 -0
- data/test/fuby/deep.rb +0 -0
- data/test/fuby/deep_each.rb +0 -0
- data/test/fuby/define_missing_method.rb +33 -0
- data/test/fuby/define_tok.rb +0 -0
- data/test/fuby/descendants.rb +0 -0
- data/test/fuby/dimension.rb +0 -0
- data/test/fuby/drop.rb +28 -0
- data/test/fuby/drop_until.rb +26 -0
- data/test/fuby/drop_while.rb +26 -0
- data/test/fuby/each.rb +0 -0
- data/test/fuby/each_with_index_or_key.rb +22 -0
- data/test/fuby/eql.rb +0 -0
- data/test/fuby/eql_componentwise.rb +0 -0
- data/test/fuby/equivalence.rb +0 -0
- data/test/fuby/eval.rb +0 -0
- data/test/fuby/extend.rb +20 -0
- data/test/fuby/format.rb +0 -0
- data/test/fuby/include.rb +20 -0
- data/test/fuby/index_or_key.rb +0 -0
- data/test/fuby/instance_attributes.rb +0 -0
- data/test/fuby/intercept.rb +16 -0
- data/test/fuby/invert.rb +0 -0
- data/test/fuby/longest_common.rb +0 -0
- data/test/fuby/matches.rb +0 -0
- data/test/fuby/matches_componentwise.rb +0 -0
- data/test/fuby/matches_prefix_of.rb +0 -0
- data/test/fuby/matches_suffix_of.rb +0 -0
- data/test/fuby/member.rb +0 -0
- data/test/fuby/merge.rb +0 -0
- data/test/fuby/merge_css.rb +0 -0
- data/test/fuby/method_added_as.rb +0 -0
- data/test/fuby/method_added_as_binary_operator.rb +20 -0
- data/test/fuby/method_added_as_filter.rb +28 -0
- data/test/fuby/new.rb +3 -0
- data/test/fuby/not.rb +0 -0
- data/test/fuby/opposite.rb +0 -0
- data/test/fuby/or.rb +19 -0
- data/test/fuby/otherwise.rb +30 -0
- data/test/fuby/part_of.rb +0 -0
- data/test/fuby/plus.rb +0 -0
- data/test/fuby/pop.rb +0 -0
- data/test/fuby/pop_if.rb +31 -0
- data/test/fuby/pop_options.rb +31 -0
- data/test/fuby/pop_unless.rb +0 -0
- data/test/fuby/pop_until.rb +0 -0
- data/test/fuby/pop_while.rb +0 -0
- data/test/fuby/prefix_of.rb +0 -0
- data/test/fuby/prefixes.rb +13 -0
- data/test/fuby/prepend.rb +34 -0
- data/test/fuby/private.rb +0 -0
- data/test/fuby/protected.rb +0 -0
- data/test/fuby/public.rb +0 -0
- data/test/fuby/push.rb +0 -0
- data/test/fuby/push_options.rb +32 -0
- data/test/fuby/random.rb +0 -0
- data/test/fuby/self_and_descendants.rb +0 -0
- data/test/fuby/shift.rb +0 -0
- data/test/fuby/shift_if.rb +0 -0
- data/test/fuby/shift_options.rb +0 -0
- data/test/fuby/shift_unless.rb +0 -0
- data/test/fuby/shift_until.rb +0 -0
- data/test/fuby/shift_while.rb +0 -0
- data/test/fuby/splat.rb +0 -0
- data/test/fuby/strip.rb +0 -0
- data/test/fuby/submodule.rb +15 -0
- data/test/fuby/suffix_of.rb +0 -0
- data/test/fuby/suffixes.rb +13 -0
- data/test/fuby/take.rb +0 -0
- data/test/fuby/take_until.rb +0 -0
- data/test/fuby/take_while.rb +0 -0
- data/test/fuby/tap.rb +58 -0
- data/test/fuby/to_boolean.rb +31 -0
- data/test/fuby/to_camel_case.rb +15 -0
- data/test/fuby/to_components.rb +0 -0
- data/test/fuby/to_dash_case.rb +15 -0
- data/test/fuby/to_hash.rb +23 -0
- data/test/fuby/to_pred.rb +25 -0
- data/test/fuby/to_proc.rb +56 -0
- data/test/fuby/to_regexp.rb +38 -0
- data/test/fuby/to_snake_case.rb +15 -0
- data/test/fuby/to_tok.rb +0 -0
- data/test/fuby/tok.rb +0 -0
- data/test/fuby/tok_arity.rb +0 -0
- data/test/fuby/tok_direction.rb +0 -0
- data/test/fuby/tok_parity.rb +0 -0
- data/test/fuby/tok_side.rb +0 -0
- data/test/fuby/try.rb +52 -0
- data/test/fuby/try_each.rb +30 -0
- data/test/fuby/try_eval.rb +34 -0
- data/test/fuby/try_exec.rb +0 -0
- data/test/fuby/unabbreviation.rb +25 -0
- data/test/fuby/unshift.rb +0 -0
- data/test/fuby/unshift_options.rb +0 -0
- data/test/fuby/uuid.rb +31 -0
- data/test/fuby/version.rb +0 -0
- metadata +369 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'fuby/pop_options'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Array do
|
6
|
+
describe "pop_options" do
|
7
|
+
it "pops the last element if is_a? Hash" do
|
8
|
+
|
9
|
+
xs = [1, 2, 3, { a:1 }]
|
10
|
+
xs.pop_options.must_equal a:1
|
11
|
+
xs.must_equal [1, 2, 3]
|
12
|
+
|
13
|
+
end
|
14
|
+
it "creates and returns a new hash unless the last element is_a? Hash" do
|
15
|
+
|
16
|
+
xs = [1, 2, 3]
|
17
|
+
xs.pop_options.must_equal Hash.new
|
18
|
+
xs.must_equal [1, 2, 3]
|
19
|
+
|
20
|
+
end
|
21
|
+
it "merges any given options as defaults" do
|
22
|
+
|
23
|
+
xs = [1, 2, 3, { a:1, b:2, c:3 }]
|
24
|
+
xs.pop_options({ b:20 }, c:300).must_equal a:1, b:2, c:3
|
25
|
+
|
26
|
+
xs = [1, 2, 3, { a:1 }]
|
27
|
+
xs.pop_options({ b:20, c:30 }, c:300).must_equal a:1, b:20, c:30
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'fuby/prepend'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Module do
|
6
|
+
describe "prepend &block" do
|
7
|
+
it "creates and prepends a module based on the given &block" do
|
8
|
+
|
9
|
+
klass = Class.new do
|
10
|
+
|
11
|
+
include Module.new {
|
12
|
+
def foo
|
13
|
+
'1st'
|
14
|
+
end
|
15
|
+
}
|
16
|
+
|
17
|
+
def foo
|
18
|
+
'2nd' + super
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
klass.prepend! do
|
23
|
+
|
24
|
+
def foo
|
25
|
+
'3rd' + super
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
klass.new.must_respond_to :foo
|
30
|
+
klass.new.foo.must_equal '3rd2nd1st'
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
File without changes
|
File without changes
|
data/test/fuby/public.rb
ADDED
File without changes
|
data/test/fuby/push.rb
ADDED
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'fuby/push_options'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Array do
|
6
|
+
describe "push_options" do
|
7
|
+
it "returns the last element if is_a? Hash" do
|
8
|
+
|
9
|
+
opt = { a: 1 }
|
10
|
+
xs = [1, 2, 3, opt]
|
11
|
+
xs.push_options.must_be_same_as opt
|
12
|
+
xs.must_equal [1, 2, 3, opt]
|
13
|
+
|
14
|
+
end
|
15
|
+
it "creates and returns a new hash which is pushed onto self" do
|
16
|
+
|
17
|
+
xs = [1, 2, 3]
|
18
|
+
xs.push_options.must_equal Hash.new
|
19
|
+
xs.must_equal [1, 2, 3, Hash.new]
|
20
|
+
|
21
|
+
end
|
22
|
+
it "merges any given options as defaults" do
|
23
|
+
|
24
|
+
xs = [1, 2, 3, { a:1, b:2, c:3 }]
|
25
|
+
xs.push_options({ b:20 }, c:300).must_equal a:1, b:2, c:3
|
26
|
+
|
27
|
+
xs = [1, 2, 3]
|
28
|
+
xs.push_options({ b:20, c:30 }, c:300).must_equal b:20, c:30
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/fuby/random.rb
ADDED
File without changes
|
File without changes
|
data/test/fuby/shift.rb
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/fuby/splat.rb
ADDED
File without changes
|
data/test/fuby/strip.rb
ADDED
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fuby/submodule'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Module do
|
6
|
+
describe "submodule *includes" do
|
7
|
+
it "returns a new module including self and the given *includes" do
|
8
|
+
|
9
|
+
includes = [Module.new, Module.new, Module.new]
|
10
|
+
|
11
|
+
Module.new.submodule *includes
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
data/test/fuby/take.rb
ADDED
File without changes
|
File without changes
|
File without changes
|
data/test/fuby/tap.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'fuby/tap'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Object do
|
6
|
+
%w{ tap tap? tap! }.each { |w| eval %{
|
7
|
+
describe :#{ w } do
|
8
|
+
it "returns self unless block_given?" do
|
9
|
+
|
10
|
+
obj = Object.new
|
11
|
+
obj.must_be_same_as obj.#{ w }
|
12
|
+
|
13
|
+
end
|
14
|
+
it "calls the given block with self, and returns self" do
|
15
|
+
|
16
|
+
obj = Object.new
|
17
|
+
obj.#{ w } { |arg| arg.must_be_same_as obj }.must_be_same_as obj
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
}}
|
22
|
+
end
|
23
|
+
describe NilClass do
|
24
|
+
describe :tap do
|
25
|
+
it "calls the block_given with self, and returns self" do
|
26
|
+
|
27
|
+
called = false
|
28
|
+
nil.tap { called = true }
|
29
|
+
called.must_equal true
|
30
|
+
nil.tap { |arg| arg.must_be_nil }.must_be_nil
|
31
|
+
nil.tap.must_be_nil
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
%w{ tap? tap_each }.each { |w| eval %{
|
36
|
+
|
37
|
+
describe :#{ w } do
|
38
|
+
it "returns self without calling the block_given" do
|
39
|
+
|
40
|
+
called = false
|
41
|
+
nil.#{ w } { called = true }
|
42
|
+
called.must_equal false
|
43
|
+
nil.#{ w } { 99 }.must_be_nil
|
44
|
+
nil.#{ w }.must_be_nil
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
}}
|
50
|
+
describe :tap! do
|
51
|
+
it "raises TypeError" do
|
52
|
+
|
53
|
+
nil.tap! { 99 }.must_raise TypeError rescue nil
|
54
|
+
nil.tap!.must_raise TypeError rescue nil
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'fuby/to_boolean'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Numeric do
|
6
|
+
describe "to_boolean" do
|
7
|
+
it "converts self to a boolean according to the common interpretation" do
|
8
|
+
|
9
|
+
0.to_boolean.must_equal false
|
10
|
+
1.to_boolean.must_equal true
|
11
|
+
+0.1.to_boolean.must_equal true
|
12
|
+
-0.1.to_boolean.must_equal false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe String do
|
18
|
+
describe "to_boolean" do
|
19
|
+
it "converts self to a boolean according to the common interpretation" do
|
20
|
+
|
21
|
+
"1".to_boolean.must_equal true
|
22
|
+
"t".to_boolean.must_equal true
|
23
|
+
"true".to_boolean.must_equal true
|
24
|
+
"TRUE".to_boolean.must_equal true
|
25
|
+
"yes".to_boolean.must_equal true
|
26
|
+
"y".to_boolean.must_equal true
|
27
|
+
"goo".to_boolean.must_equal false
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fuby/to_camel_case'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Symbol do
|
6
|
+
describe "to_camelCase" do
|
7
|
+
it "converts self to a camelCase symbol" do
|
8
|
+
|
9
|
+
:html5_the_5th_element.to_camelCase.must_equal :html5The5thElement
|
10
|
+
:HTML5TH.to_CamelCase.must_equal :Html5th
|
11
|
+
:HTML5th.to_CamelCase.must_equal :HTML5th
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fuby/to_dash_case'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Symbol do
|
6
|
+
describe "to_dash_case" do
|
7
|
+
it "converts self to a dash-case symbol" do
|
8
|
+
|
9
|
+
:html5_the_5th_element.to_dash_case.must_equal :"html5-the-5th-element"
|
10
|
+
:HTML5TH.to_dash_case.must_equal :"html-5th"
|
11
|
+
:HTML5th.to_dash_case.must_equal :"html-5th"
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'fuby/to_hash'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Enumerable do
|
6
|
+
describe "to_hash" do
|
7
|
+
it "returns a Hash with the indicies of self as keys" do
|
8
|
+
|
9
|
+
[1, 2, 3].to_hash.must_equal 0 => 1, 1 => 2, 2 => 3
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Hash do
|
16
|
+
describe "to_hash" do
|
17
|
+
it "returns a copy of self" do
|
18
|
+
|
19
|
+
{ a:1 }.must_equal a:1
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'fuby/to_pred'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Module do
|
6
|
+
describe "to_pred" do
|
7
|
+
it "returns a Proc that returns whether its argument kind_of? self" do
|
8
|
+
|
9
|
+
Symbol.to_pred.call(:foo).must_equal true
|
10
|
+
Symbol.to_pred.call('foo').must_equal false
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Regexp do
|
17
|
+
describe "to_pred" do
|
18
|
+
it "returns a Proc that returns whether its argument matches self" do
|
19
|
+
|
20
|
+
/foo/.to_pred.call(:foo).must_equal true
|
21
|
+
/foo/.to_pred.call('foo').must_equal true
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'fuby/to_proc'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Array do
|
6
|
+
describe "to_proc" do
|
7
|
+
it "returns a Proc that interprets `self` as a lookup table" do
|
8
|
+
|
9
|
+
[1, 2, 3].to_proc.call(1).must_equal 2
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Hash do
|
16
|
+
describe "to_proc" do
|
17
|
+
it "returns a Proc that interprets `self` as a fuzzy lookup table" do
|
18
|
+
|
19
|
+
{ /foo/ => true, /bar/ => false }.to_proc.call('foo').must_equal true
|
20
|
+
{ Integer => true, Float => false }.to_proc.call(4).must_equal true
|
21
|
+
|
22
|
+
[1, 1.0].map(&{ Integer => true, Float => false }.to_proc).must_equal [true, false]
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe String do
|
29
|
+
describe "to_proc" do
|
30
|
+
it "returns a Proc based on `self` as a format string" do
|
31
|
+
|
32
|
+
"%s_%s".to_proc.call(5, 'a').must_equal "5_a"
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Regexp do
|
39
|
+
describe "to_proc" do
|
40
|
+
it "returns a Proc based on `self` as a grouping expression" do
|
41
|
+
|
42
|
+
/_(\w+)_/.to_proc.call("_foo_").must_equal "foo"
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe Integer do
|
49
|
+
describe "to_proc" do
|
50
|
+
it "returns a Proc that takes an array and returns the element at this index" do
|
51
|
+
|
52
|
+
1.to_proc.call([1, 2]).must_equal 2
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'fuby/to_regexp'
|
2
|
+
|
3
|
+
using Fuby
|
4
|
+
|
5
|
+
describe Regexp do
|
6
|
+
describe "to_regexp" do
|
7
|
+
it "returns a copy of self" do
|
8
|
+
|
9
|
+
re = /fun/
|
10
|
+
re.to_regexp.must_equal re.dup
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Array do
|
17
|
+
describe "to_regexp" do
|
18
|
+
it "returns the disjunction of terms contained in self" do
|
19
|
+
|
20
|
+
[ /abra/, /cadabra/ ].to_regexp.must_equal /abra|cadabra/
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe String do
|
27
|
+
describe "to_regexp" do
|
28
|
+
it "returns a Regexp that matches this string exactly" do
|
29
|
+
|
30
|
+
"foo".must_match "foo".to_regexp
|
31
|
+
"__foo__".must_match "foo".to_regexp
|
32
|
+
"a foo".must_match "foo".to_regexp
|
33
|
+
"a food".wont_match "foo".to_regexp
|
34
|
+
"food".wont_match "foo".to_regexp
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|