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: 5e6a058c7448c3b6509f06094c0a87e0c461f76a
4
- data.tar.gz: a762394265c6944cee3c03c425db229be6413461
3
+ metadata.gz: 6b1639844409b11e7f45fc554f83432734d3e3ee
4
+ data.tar.gz: dd9233d2232ba3a36234142c6764af894fbbf012
5
5
  SHA512:
6
- metadata.gz: 3b573bdc654d513ea128b8365b55673635de52bea8c70d0a98430f907efb661693dfb1a92fc05025b76cdc98d9c476d011f514f97be58a28d586837632305a9d
7
- data.tar.gz: 19f94cca7c6ca5920209c1565c09ccaba9d5d910699144016780e1fdd61131b531ecef00608d5e9c985779675c0c3f937b52b5c084ff762dde22d0c1a50dda52
6
+ metadata.gz: d7f43e4b30f3279ac854cb646e1171825397ada05f28b78b78422a28da00717df3d58db26326d34755d823be27951f69631efa948253c972d204a11f59ce0d7b
7
+ data.tar.gz: 4875cda1e30239bedd021042bd1972e98d21453099676d3b690e239855f24f07a244737190edb61043ec42fa3306b051f6a517518aae4c4b6f563edc7e2151d5
@@ -1,18 +1,20 @@
1
1
  require 'matrix'
2
2
 
3
3
  class Array
4
- # Converts an array, whose elements are also arrays, to a hash. Head
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
- def to_hash( tail_from = 1 )
11
- self.reject { | e | e[0].nil? }.reduce({}) { |a, e|
12
- tail = e[tail_from..-1]
13
- a.merge( { e[0] => tail.size >= 2 ? tail : tail[0] } )
14
- }
15
- end
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. Optional argument +:overwrite_methods+ enables the
6
- # readers to overwrite existing methods.
5
+ # getter (reader) methods. Raises NameError should any of the getters shadow /
6
+ # overwrite existing methods.
7
7
  #
8
- def set_attr_with_readers( hash )
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
- # Makes the receiver own parametrized subclasses of the supplied classes.
18
- # Expects a hash of pairs { reader_symbol: class }, and a hash of parameters,
19
- # with which the class(es) is (are) parametrized. Parametrized subclasses
20
- # are made accessible under the supplied reader symbol.
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 new! *args, &block
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
@@ -1,3 +1,3 @@
1
1
  module YSupport
2
- VERSION = "2.0.26"
2
+ VERSION = "2.0.28"
3
3
  end
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.26
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-26 00:00:00.000000000 Z
11
+ date: 2013-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport