little_sugar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/little_sugar.rb +77 -0
- metadata +63 -0
data/lib/little_sugar.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'unicode'
|
2
|
+
|
3
|
+
class Array
|
4
|
+
|
5
|
+
def uniq_by(&mtd)
|
6
|
+
transforms = []
|
7
|
+
self.select do |el|
|
8
|
+
should_keep = !transforms.include?(t=mtd[el])
|
9
|
+
transforms << t
|
10
|
+
should_keep
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def uniq_by!(&mtd)
|
15
|
+
self.replace uniq_by(&mtd)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Сортировка по методу &mtd элементов массива
|
19
|
+
def sort_by(&mtd)
|
20
|
+
self.sort { |a,b| mtd[a] <=> mtd[b] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def sort_by!(&mtd)
|
24
|
+
self.sort!{ |a,b| mtd[a] <=> mtd[b] }
|
25
|
+
end
|
26
|
+
|
27
|
+
# Элементы массива вперемешку
|
28
|
+
def mix
|
29
|
+
duplicated_original, new_array = self.dup, self.class.new
|
30
|
+
new_array << duplicated_original.slice!(Kernel.rand(duplicated_original.size)) \
|
31
|
+
until new_array.size.eql?(self.size)
|
32
|
+
new_array
|
33
|
+
end
|
34
|
+
|
35
|
+
def mix!
|
36
|
+
self.replace(mix)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
class Object
|
42
|
+
|
43
|
+
# Объект - не nil?
|
44
|
+
# Для упрощения записи некоторых условий
|
45
|
+
def not_nil?
|
46
|
+
!self.nil?
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
class String
|
52
|
+
|
53
|
+
def downcase_utf8
|
54
|
+
Unicode::downcase(self)
|
55
|
+
end
|
56
|
+
|
57
|
+
def downcase_utf8!
|
58
|
+
self.replace downcase_utf8
|
59
|
+
end
|
60
|
+
|
61
|
+
def upcase_utf8
|
62
|
+
Unicode::upcase(self)
|
63
|
+
end
|
64
|
+
|
65
|
+
def upcase_utf8!
|
66
|
+
self.replace upcase_utf8
|
67
|
+
end
|
68
|
+
|
69
|
+
def capitalize_utf8
|
70
|
+
Unicode::capitalize(self)
|
71
|
+
end
|
72
|
+
|
73
|
+
def capitalize_utf8!
|
74
|
+
self.replace capitalize_utf8
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: little_sugar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ilya Boltnev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: unicode
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.4.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.4.4
|
30
|
+
description: A bit of ruby syntax sugar for comfortable work with arrays and utf-8
|
31
|
+
strings
|
32
|
+
email: ilya@boltnev.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/little_sugar.rb
|
38
|
+
homepage: https://github.com/boltnev/ruby_core_extensions
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.24
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: A bit of ruby syntax sugar
|
62
|
+
test_files: []
|
63
|
+
has_rdoc:
|