-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby cheats
54 lines (45 loc) · 1.01 KB
/
ruby cheats
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
ARRAY
[1,2].max|min
[2,1].sort = [1,2]
[1,2].join(",") = "1,2"
[a,b,c] & [b,c,d] returns [b,c] (intersection)
[a,b] + [c] = [a,b,c]
[a,b] << c = [a,b,c]
ITERATORS
.each
.collect/map
MATHS
** (exponent) e.g **2 = square
PRINTF
<format> % number
"%03d" : min. 3 characters , puts 2 leading zeroes if 1 digit
REGEX
string =~ /r/
string.scan(r)
string.match(r)
string.gsub/sub(r,'substituted_text')
SWITCH
case var
when value
else
end
TIME
strftime("due on %B %d at %I:%M %p")
Year: Y/y
Month: m/b/B
Date: d/-d
Day: a/A
METHOD
Method is an object
Time.method :now will return a Time.now method object
can 'call' a method_object to execute it
CLASS
def initialize(params)
class A < B (inherits B's public methods.B is not instantiated)
class A < B::C (Where B is the module holding the C class)
can re-open B's method in A
Reopen method is overriden
To superimpose, add "super"
To make it's variables available, use attr_accessor
Length
truncate(string, length:80, separator: ' ')