core_extensions 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/core_extensions.gemspec +2 -0
- data/lib/core_extensions/array.rb +21 -0
- data/lib/core_extensions/float.rb +9 -0
- data/lib/core_extensions/hash.rb +10 -0
- data/lib/core_extensions/integer.rb +5 -0
- data/lib/core_extensions/nil.rb +5 -0
- data/lib/core_extensions/object.rb +25 -0
- data/lib/core_extensions/string.rb +10 -0
- data/lib/core_extensions/symbol.rb +5 -0
- data/lib/core_extensions/version.rb +1 -1
- metadata +21 -2
data/core_extensions.gemspec
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Array
|
2
|
+
def to_h
|
3
|
+
Hash[self]
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_data
|
7
|
+
map(&:to_h)
|
8
|
+
end
|
9
|
+
|
10
|
+
def map_to(field)
|
11
|
+
self.map { |hash| hash[field] }
|
12
|
+
end
|
13
|
+
|
14
|
+
def exclude?(value)
|
15
|
+
!include?(value)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash_with_indexes_as_keys
|
19
|
+
each_with_index.map { |option,index| [index,option] }.to_h
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Hash
|
2
|
+
def to_ostruct(klass = OpenStruct, cch = {})
|
3
|
+
cch[self] = klass.new
|
4
|
+
each do |key,value|
|
5
|
+
raise "Invalid key: #{ key }" unless key =~ /[a-z_][a-zA-Z0-9_]*/
|
6
|
+
cch[self].__send__ "#{ key }=", value.is_a?(Hash) ? cch[value] || value.send(__method__,klass,cch) : value
|
7
|
+
end
|
8
|
+
cch[self]
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Object
|
2
|
+
def self.find_all_descendents_of(parent_klass)
|
3
|
+
ObjectSpace.each_object(Class).select { |klass| klass < parent_klass }
|
4
|
+
end
|
5
|
+
|
6
|
+
def try(method)
|
7
|
+
send method rescue nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def present?
|
11
|
+
if respond_to? :blank?
|
12
|
+
!blank?
|
13
|
+
else
|
14
|
+
!nil?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(method, *args, &block)
|
19
|
+
if Object.const_defined?('Platform') && Platform.respond_to?(method)
|
20
|
+
Platform.send method, *args, &block
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: core_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sarkis Karayan
|
@@ -10,7 +10,18 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-09-13 00:00:00.000000000Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
version_requirements: &2056 !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
none: false
|
22
|
+
requirement: *2056
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
14
25
|
description: Ruby Core Object Extensions
|
15
26
|
email:
|
16
27
|
- skarayan@gmail.com
|
@@ -25,6 +36,14 @@ files:
|
|
25
36
|
- Rakefile
|
26
37
|
- core_extensions.gemspec
|
27
38
|
- lib/core_extensions.rb
|
39
|
+
- lib/core_extensions/array.rb
|
40
|
+
- lib/core_extensions/float.rb
|
41
|
+
- lib/core_extensions/hash.rb
|
42
|
+
- lib/core_extensions/integer.rb
|
43
|
+
- lib/core_extensions/nil.rb
|
44
|
+
- lib/core_extensions/object.rb
|
45
|
+
- lib/core_extensions/string.rb
|
46
|
+
- lib/core_extensions/symbol.rb
|
28
47
|
- lib/core_extensions/version.rb
|
29
48
|
homepage: https://github.com/skarayan/core_extensions
|
30
49
|
licenses: []
|