y_support 2.0.38 → 2.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +52 -19
- data/lib/y_support/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ed2dababbc49adf84a88b8412d7d8a52d2106c5c
|
|
4
|
+
data.tar.gz: afbdb0ab6c8a7dada0c501a4757b01b850afeba6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52cc87bbe3e00e2ba464787745f4f2ea246423c7f0e530666c05aa88397c1cefb2dddfcb6d61dc4ed0e810f32b97053bad2cc7ea2cfa9715e4592f8627dbaccb
|
|
7
|
+
data.tar.gz: 25f0078f9df59bbec95f830f5fb3702ad7e6e2b046e5f420bd64ae73437ae2bc3a8fc876ea529d9c2d978efcf7b8f6f6699ee4013240dcc3b7e3465e0f20b6c0
|
data/README.md
CHANGED
|
@@ -1,24 +1,57 @@
|
|
|
1
1
|
# YSupport
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
`YSupport` is a common support library for Y* gems (`y_petri`, `yzz`,
|
|
4
|
+
`y_nelson`, `sy`...). At the moment, it is a collection of all and sundry
|
|
5
|
+
helpful methods, which can be divided as follows
|
|
6
|
+
|
|
7
|
+
* `NameMagic` (`lib/name_magic.rb`) -- its main feature is that it allows
|
|
8
|
+
constant magic known from classes to work with any objects.
|
|
9
|
+
* Miscellaneous helpful methods (`lib/misc.rb`)
|
|
10
|
+
* Typing (runtime assertions, `lib/typing.rb`)
|
|
11
|
+
* Other smaller components:
|
|
12
|
+
- `unicode.rb` -- shortcut letter for class (ç), singleton class (ⓒ) etc.
|
|
13
|
+
- `null_object.rb`
|
|
14
|
+
- `try.rb` -- a different kind of `#try` method
|
|
15
|
+
- several other small fry components
|
|
16
|
+
|
|
17
|
+
## NameMagic
|
|
18
|
+
|
|
19
|
+
Try for example:
|
|
20
|
+
```ruby
|
|
21
|
+
require 'y_support/name_magic'
|
|
22
|
+
|
|
23
|
+
class Animal
|
|
24
|
+
include NameMagic
|
|
25
|
+
def sound; "squeak" end
|
|
26
|
+
def speak; 2.times { puts sound.capitalize << ?! } end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class Dog < Animal; def sound; "bark" end end
|
|
30
|
+
class Cat < Animal; def sound; "meow" end end
|
|
31
|
+
|
|
32
|
+
Pochi = Dog.new
|
|
33
|
+
unnamed_kitten = Cat.new
|
|
34
|
+
```
|
|
35
|
+
Mixin `NameMagic` makes class `Animal` keep registry of its instances:
|
|
36
|
+
```ruby
|
|
37
|
+
Animal.instances.names
|
|
38
|
+
#=> [:Pochi, nil]
|
|
39
|
+
Tama = unnamed_kitten
|
|
40
|
+
Animal.instances.names
|
|
41
|
+
#=> [:Pochi, :Tama]
|
|
42
|
+
Cheburashka = Animal.new
|
|
43
|
+
Animal.instances.names
|
|
44
|
+
#=> [:Pochi, :Tama, :Cheburashka]
|
|
45
|
+
Dog.instances.names
|
|
46
|
+
#=> [:Pochi]
|
|
47
|
+
Animal.instances.each &:speak
|
|
48
|
+
Dog.instances.each &:speak
|
|
49
|
+
Cat.instances.each &:speak
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Other components
|
|
53
|
+
|
|
54
|
+
Read the documentation of the individual methods.
|
|
22
55
|
|
|
23
56
|
## Contributing
|
|
24
57
|
|
data/lib/y_support/version.rb
CHANGED