toomuchsupport 0.0.01
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/core_ext/array.rb +31 -0
- data/lib/core_ext/constants.rb +1 -0
- data/lib/core_ext/core_ext.rb +5 -0
- data/lib/core_ext/integer.rb +26 -0
- data/lib/core_ext/object.rb +8 -0
- data/lib/core_ext/string.rb +26 -0
- data/lib/toomuchsupport.rb +7 -0
- metadata +51 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
class Array
|
2
|
+
# let's make some "useful" aliases
|
3
|
+
def has? value
|
4
|
+
include? value
|
5
|
+
end
|
6
|
+
|
7
|
+
def haz? value
|
8
|
+
include? value
|
9
|
+
end
|
10
|
+
|
11
|
+
# having only first and last mehods is far too boring
|
12
|
+
# let's define methods for every index up to 99/100th :)
|
13
|
+
|
14
|
+
words = %w{
|
15
|
+
first second third fourth fifth sixth seventh eighth ninth tenth
|
16
|
+
eleventh twelfth thirteenth fourteenth fifteenth sixteenth seventeenth eighteenth ninteenth
|
17
|
+
}
|
18
|
+
|
19
|
+
TMS_TENS.each do |ten|
|
20
|
+
words << ten.gsub('y','ieth')
|
21
|
+
1.upto(9) { |n| words << "#{ten}#{words[n-1]}" }
|
22
|
+
end
|
23
|
+
|
24
|
+
words << "onehundreth"
|
25
|
+
|
26
|
+
words.each_with_index do |word, index|
|
27
|
+
define_method word do
|
28
|
+
self[index]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
TMS_TENS = %w{ twenty thirty fourty fifty sixty seventy eighty ninety }
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Integer
|
2
|
+
# no comment required
|
3
|
+
def is_the_meaning_of_life?
|
4
|
+
self == 42
|
5
|
+
end
|
6
|
+
|
7
|
+
# and now, in the spirit of #zero?
|
8
|
+
# we have #one? #two? #three?...
|
9
|
+
words = %w{
|
10
|
+
one two three four five six seven eight nine ten
|
11
|
+
eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen ninteen
|
12
|
+
}
|
13
|
+
|
14
|
+
TMS_TENS.each do |ten|
|
15
|
+
words << ten
|
16
|
+
1.upto(9) { |n| words << "#{ten}#{words[n-1]}" }
|
17
|
+
end
|
18
|
+
|
19
|
+
words << "onehundred"
|
20
|
+
|
21
|
+
words.each_with_index do |word, index|
|
22
|
+
define_method "#{word}?".to_sym do
|
23
|
+
self == index + 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class String
|
2
|
+
# remove last (or more) chars from string
|
3
|
+
def clip n=1
|
4
|
+
self[0..-n-1]
|
5
|
+
end
|
6
|
+
|
7
|
+
def clip! n=1
|
8
|
+
self.replace(clip n)
|
9
|
+
end
|
10
|
+
|
11
|
+
# this is truly a magnificent core extension
|
12
|
+
# it let's you do stuff like "foo".foo? # => true
|
13
|
+
# TODO: fuzzy matching for underscores/spaces
|
14
|
+
def method_missing sym
|
15
|
+
raise NoMethodError.new("Undefined method #{sym} for String") unless sym.to_s.end_with? "?"
|
16
|
+
this = self.downcase.gsub("_"," ")
|
17
|
+
that = sym.to_s.clip # remove ?
|
18
|
+
that = that.downcase.gsub("_"," ")
|
19
|
+
this == that
|
20
|
+
end
|
21
|
+
|
22
|
+
# this handy little helper evals code the OO way :)
|
23
|
+
def to_proc
|
24
|
+
eval "Proc.new do\n#{self}\nend"
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: toomuchsupport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.01
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alex Coplan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Enough support for anyone
|
15
|
+
email: lexy0202@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/core_ext/array.rb
|
21
|
+
- lib/core_ext/constants.rb
|
22
|
+
- lib/core_ext/core_ext.rb
|
23
|
+
- lib/core_ext/integer.rb
|
24
|
+
- lib/core_ext/object.rb
|
25
|
+
- lib/core_ext/string.rb
|
26
|
+
- lib/toomuchsupport.rb
|
27
|
+
homepage: http://github.com/alexcoplan/toomuchsupport
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 1.8.24
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: Too Much Support
|
51
|
+
test_files: []
|