y_support 2.0.26 → 2.0.28
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b1639844409b11e7f45fc554f83432734d3e3ee
|
4
|
+
data.tar.gz: dd9233d2232ba3a36234142c6764af894fbbf012
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f43e4b30f3279ac854cb646e1171825397ada05f28b78b78422a28da00717df3d58db26326d34755d823be27951f69631efa948253c972d204a11f59ce0d7b
|
7
|
+
data.tar.gz: 4875cda1e30239bedd021042bd1972e98d21453099676d3b690e239855f24f07a244737190edb61043ec42fa3306b051f6a517518aae4c4b6f563edc7e2151d5
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'matrix'
|
2
2
|
|
3
3
|
class Array
|
4
|
-
#
|
5
|
-
# (position 0) of each array is made to point at the rest of the array
|
6
|
-
# (tail), normally starting immediately after the head (position 1). The
|
7
|
-
# starting position of the tail can be controlled by an optional
|
8
|
-
# argument. Tails of 2 and more elements are represented as arrays.
|
4
|
+
# This would collide with built-in #to_hash method.
|
9
5
|
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
# # Converts an array, whose elements are also arrays, to a hash. Head
|
7
|
+
# # (position 0) of each array is made to point at the rest of the array
|
8
|
+
# # (tail), normally starting immediately after the head (position 1). The
|
9
|
+
# # starting position of the tail can be controlled by an optional
|
10
|
+
# # argument. Tails of 2 and more elements are represented as arrays.
|
11
|
+
# #
|
12
|
+
# def to_hash( tail_from = 1 )
|
13
|
+
# self.reject { | e | e[0].nil? }.reduce({}) { |a, e|
|
14
|
+
# tail = e[tail_from..-1]
|
15
|
+
# a.merge( { e[0] => tail.size >= 2 ? tail : tail[0] } )
|
16
|
+
# }
|
17
|
+
# end
|
16
18
|
|
17
19
|
# Zips this array with another collection into a hash. If a block is given,
|
18
20
|
# it is applied to each element of the array to get the hash values.
|
@@ -2,22 +2,31 @@
|
|
2
2
|
|
3
3
|
class Object
|
4
4
|
# Assigns prescribed atrributes to the object and makes them accessible with
|
5
|
-
# getter (reader) methods.
|
6
|
-
#
|
5
|
+
# getter (reader) methods. Raises NameError should any of the getters shadow /
|
6
|
+
# overwrite existing methods.
|
7
7
|
#
|
8
|
-
def set_attr_with_readers
|
8
|
+
def set_attr_with_readers hash
|
9
|
+
hash.each_pair { |ß, value|
|
10
|
+
fail NameError, "Method \##{ß} already defined!" if methods.include? ß
|
11
|
+
set_attr_with_readers! ß => value
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Assigns prescribed atrributes to the object and makes them accessible with
|
16
|
+
# getter (reader) methods. Shadows / overwrites existing methods.
|
17
|
+
#
|
18
|
+
def set_attr_with_readers! hash
|
9
19
|
hash.each_pair { |symbol, value|
|
10
20
|
instance_variable_set "@#{symbol}", value
|
11
|
-
fail NameError, "Method \##{symbol} already defined!" if
|
12
|
-
methods.include? symbol unless hash[:overwrite_methods] == true
|
13
21
|
singleton_class.class_exec { attr_reader symbol }
|
14
22
|
}
|
15
23
|
end
|
16
24
|
|
17
|
-
#
|
18
|
-
# Expects a hash of pairs { reader_symbol:
|
19
|
-
# with which the class(es) is (are)
|
20
|
-
#
|
25
|
+
# Constructs parametrized subclasses of the supplied classes and makes them
|
26
|
+
# available under specified getters. Expects a hash of pairs { reader_symbol:
|
27
|
+
# class }, and a hash of parameters, with which the class(es) is (are)
|
28
|
+
# parametrized. Raises NameError should any of the getters shadow / overwrite
|
29
|
+
# existing methods.
|
21
30
|
#
|
22
31
|
def param_class hash, with: (fail ArgumentError, "No parameters!")
|
23
32
|
hash.each { |ß, ç|
|
@@ -26,4 +35,17 @@ class Object
|
|
26
35
|
}
|
27
36
|
return nil
|
28
37
|
end
|
38
|
+
|
39
|
+
# Constructs parametrized subclasses of the supplied classes and makes them
|
40
|
+
# available under specified getters. Expects a hash of pairs { reader_symbol:
|
41
|
+
# class }, and a hash of parameters, with which the class(es) is (are)
|
42
|
+
# parametrized. Shadows / overwrites existing methods.
|
43
|
+
#
|
44
|
+
def param_class! hash, with: (fail ArgumentError, "No parameters!")
|
45
|
+
hash.each { |ß, ç|
|
46
|
+
sub = ç.parametrize with
|
47
|
+
set_attr_with_readers!( ß => sub )
|
48
|
+
}
|
49
|
+
return nil
|
50
|
+
end
|
29
51
|
end
|
@@ -61,7 +61,7 @@ module NameMagic::ClassMethods
|
|
61
61
|
# Calls #new in _avid_ _mode_ (name_avid: true); see #new method for avid mode
|
62
62
|
# explanation.
|
63
63
|
#
|
64
|
-
def
|
64
|
+
def avid *args, &block
|
65
65
|
oo = args[-1].is_a?( Hash ) ? args.pop : {} # extract options
|
66
66
|
new *args, oo.update( name_avid: true ), &block
|
67
67
|
end
|
data/lib/y_support/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: y_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- boris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|