File tree 3 files changed +29
-0
lines changed
3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ The majority of these Ruby Tricks were extracted from James Edward Gray II [talk
22
22
* [ Head tail] ( tricks/head-tail.md )
23
23
* [ Inject] ( tricks/inject.md )
24
24
* [ Inspecting the source with script lines] ( tricks/inspecting-the-source-with-script-lines.md )
25
+ * [ Integer#digits] ( tricks/digits.md )
25
26
* [ Iterating over specific types] ( tricks/iterating-over-specific-types.md )
26
27
* [ Lambda your own syntax] ( tricks/lambda-your-own-syntax.md )
27
28
* [ Memoization] ( tricks/memoization.md )
Original file line number Diff line number Diff line change
1
+ ### Integer#digits
2
+
3
+ ``` ruby
4
+ awesome_number = 12345
5
+
6
+ p awesome_number.to_s.chars.map(& :to_i ).reverse
7
+
8
+ # Result:
9
+ # [5, 4, 3, 2, 1]
10
+
11
+ p awesome_number.digits
12
+
13
+ # Result:
14
+ # [5, 4, 3, 2, 1]
15
+ ```
16
+
17
+ [ View Source] ( source_code/digits.rb )
Original file line number Diff line number Diff line change
1
+ awesome_number = 12345
2
+
3
+ p awesome_number . to_s . chars . map ( &:to_i ) . reverse
4
+
5
+ # Result:
6
+ # [5, 4, 3, 2, 1]
7
+
8
+ p awesome_number . digits
9
+
10
+ # Result:
11
+ # [5, 4, 3, 2, 1]
You can’t perform that action at this time.
0 commit comments