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 @@
|
|
1
|
+
Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'fuby/prepend'
|
2
|
+
require 'fuby/to_pred'
|
3
|
+
|
4
|
+
module Fuby
|
5
|
+
refine ::Module do
|
6
|
+
|
7
|
+
def method_added_as_filter *names
|
8
|
+
names.each do |name|
|
9
|
+
prepend! do
|
10
|
+
define_method name do |match = nil, &pred|
|
11
|
+
return method name if match.nil? && pred.nil?
|
12
|
+
return super &(pred || match.to_pred)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/fuby/new.rb
ADDED
data/lib/fuby/not.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
using Fuby
|
2
|
+
|
3
|
+
module Fuby
|
4
|
+
refine ::Proc do
|
5
|
+
|
6
|
+
def not
|
7
|
+
proc { |*sig, &blk| ! call *sig, &blk }
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
refine ::TrueClass do
|
12
|
+
|
13
|
+
def not
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
refine ::FalseClass do
|
19
|
+
|
20
|
+
def not
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
using Fuby
|
2
|
+
|
3
|
+
module Fuby
|
4
|
+
|
5
|
+
refine ::Symbol do
|
6
|
+
|
7
|
+
attr_reader :opposite
|
8
|
+
|
9
|
+
def opposite= sym
|
10
|
+
raise ::ArgumentError, "`opposite` of a Symbol must be a Symbol, found #{ sym.class }: #{ sym }" unless ::Symbol === sym
|
11
|
+
raise ::ArgumentError, "`opposite` of :#{ self } already :#{ opposite }, found: #{ sym }" unless @opposite.nil? || @opposite == sym
|
12
|
+
return if @opposite == sym
|
13
|
+
@opposite = sym and sym.opposite = self
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
:up .opposite = :down
|
19
|
+
:top .opposite = :bottom
|
20
|
+
:left .opposite = :right
|
21
|
+
:first .opposite = :last
|
22
|
+
:top_left .opposite = :bottom_right
|
23
|
+
:bottom_left .opposite = :top_right
|
24
|
+
:asc .opposite = :desc
|
25
|
+
:ascending .opposite = :descending
|
26
|
+
:to .opposite = :from
|
27
|
+
:next .opposite = :previous
|
28
|
+
|
29
|
+
end
|
data/lib/fuby/or.rb
ADDED
data/lib/fuby/part_of.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'method_added_as_binary_operator'
|
2
|
+
require_relative 'eql_componentwise'
|
3
|
+
|
4
|
+
using Fuby
|
5
|
+
|
6
|
+
module Fuby
|
7
|
+
module ::Enumerable # can't refine Module
|
8
|
+
|
9
|
+
def part_of? that
|
10
|
+
count <= that.count and eql_componentwise? that
|
11
|
+
end
|
12
|
+
|
13
|
+
method_added_as_binary_operator :part_of?
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/fuby/plus.rb
ADDED
data/lib/fuby/pop.rb
ADDED
data/lib/fuby/pop_if.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Fuby
|
2
|
+
refine ::Array do
|
3
|
+
|
4
|
+
def pop_options *defaults
|
5
|
+
defaults.each_with_object (Hash === last ? pop : {}) do |dft, opt|
|
6
|
+
opt.merge!(dft) { |key, val| val }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def push_options *defaults
|
11
|
+
pop_options(*defaults).tap { |opt| push opt }
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'part_of'
|
2
|
+
|
3
|
+
module Fuby
|
4
|
+
refine ::Array do
|
5
|
+
|
6
|
+
alias_method :prefix_of?, :part_of?
|
7
|
+
alias_method :matches_prefix_of?, :matches_part_of?
|
8
|
+
|
9
|
+
method_added_as_binary_operator :prefix_of?, :matches_prefix_of?
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir.glob "*_prefix_of.rb", &method(:require)
|
data/lib/fuby/prepend.rb
ADDED
data/lib/fuby/private.rb
ADDED
data/lib/fuby/public.rb
ADDED
data/lib/fuby/push.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir.glob "#{ __FILE__.chomp ".rb" }_*.rb", &method(:require)
|
data/lib/fuby/random.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
using Fuby
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
module Fuby
|
6
|
+
refine ::Range do
|
7
|
+
|
8
|
+
def random
|
9
|
+
min + ::SecureRandom.random_number(max - min)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
refine ::String.singleton_class do
|
14
|
+
|
15
|
+
def random n = 64
|
16
|
+
::SecureRandom.random_bytes(64).codepoints.each_with_object("") { |n, s| s << n % 26 + 97 }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
refine ::Symbol.singleton_class do
|
21
|
+
|
22
|
+
def random n = nil
|
23
|
+
::String.random(n).to_sym
|
24
|
+
end
|
25
|
+
|
26
|
+
def __random__ n = 64
|
27
|
+
:"__%s__" % ::String.random(n)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/fuby/shift.rb
ADDED