-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.rb
65 lines (54 loc) · 1.29 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
ActionController::Base.helper(Bilson::Fileman)
Hash.class_eval do
def classed_values
new_opts = {}
each do |k,v|
if v == 'true'
new_opts[k.to_sym] = true
elsif v == 'false'
new_opts[k.to_sym] = false
elsif v.class == Hash
new_opts[k.to_sym] = v.classed_values
elsif v.represents_f?
new_opts[k.to_sym] = v.to_f
elsif v.represents_i?
new_opts[k.to_sym] = v.to_i
else
new_opts[k.to_sym] = v
end
end
return new_opts
end
end
String.class_eval do
# Does this value represent an integer?
def represents_i?
i_value = self.to_i
# is the string converted to int not equal to zero (because it might be a string)
if i_value != 0
# are we sure this isn't actually a float?
if (i_value - self.to_f) == 0
true
else
false
end
elsif i_value == 0
# is the value equal to the int value converted to_s?
if self == i_value.to_s
true
else
false
end
end
end
# Does this value represent a float?
def represents_f?
f_value = self.to_f
# is this not equal to zero and also not actually an integer?
if (f_value != 0) && (f_value.to_s == self)
true
else
false
end
end
end