@JanLelis β December 2018 β π½ππ²::π
Documenting lesser-known features in Ruby
??..
(endless..ranges)
Endless Range Examples
(9..).take(3)
# => [9, 10, 11]
(?a..?z).zip(?a.ord..)
# => [["a", 97], ["b", 98], ["c", 99], β¦
Poking around with ranges (1)
(nil..)
nil..
(nil..).cover?(nil)
true
(nil..).include?(nil)
TypeError (can't iterate from NilClass)
Poking around with ranges (2)
(9..).cover?(1/0.0)
true
(9...).cover?(1/0.0)
true
(9..) == (9...)
false
Poking around with ranges (3)
"Rails vs Hanami"[9..]
"Rails vs Hanami"[9..-1]
"Hanami"
(9..).size
Infinity
(9..-1).size
0
The Ruby standard library is currently
getting divided into individual gems
As of the current Ruby version,
how many standard gems do we have?
23 default gems
7 bundled gems
json, openssl, bigdecimal, fileutils, β¦
How many will be added in 2.6?
15
logger, irb, matrix, fileutils, β¦and bundler
How many libraries does the stdlib contain altogether?
107Misc fun stuff
How to produce this output? (1)
[1,2].____ { |x| [x, x**2] }
# => {1 => 1, 2 => 4}
How to produce this output? (1)
[1,2].to_h { |x| [x, x**2] }
# => {1 => 1, 2 => 4}
Before, we had to use Hash[]
How to produce this output? (2)
[*(1..20)_3]
#=> [1, 4, 7, 10, 13, 16, 19]
How to produce this output? (2)
[*(1..20)%3]
#=> [1, 4, 7, 10, 13, 16, 19]
The new Range#%
is an alias to Range#step
How to produce this output? (3)
a = (7..9).each
b = Prime.each
a._____(b).take(7)
#=> [7, 8, 9, 2, 3, 5, 7]
How to produce this output? (3)
a = (7..9).each
b = Prime.each
a.chain(b).take(7)
#=> [7, 8, 9, 2, 3, 5, 7]
Merge multiple enumerators with Enumerable#chain / +
How to charge your Ruby with superpowers?
$ ruby -S rails server
# Rails is slowβ¦
How to charge your Ruby with superpowers?
$ ruby --jit -S rails server
# Rails is around 2.6x faster!
(optimistic guess)
Powered by the new Just-In-Time compiler
Ruby 2.6 allows constants to begin with all uppercased letters!
WHICH ONE OF THE CLASS NAMES IS VALID? (1)
class β»
end
class Γtsch
end
$ uniscribe "β»"
213B ββ β» ββ FACSIMILE SIGN
WHICH ONE OF THE CLASS NAMES IS VALID? (2)
class ΔΏogger
end
class κ‘ogger
end
$ uniscribe "ΔΏκ‘"
013F ββ ΔΏ ββ LATIN CAPITAL LETTER L WITH MIDDLE DOT
A4E1 ββ κ‘ ββ LISU LETTER LA
WHICH ONE OF THE CLASS NAMES IS VALID? (3)
class Ξ
end
class π
end
$ uniscribe "Ξπ"
0394 ββ Ξ ββ GREEK CAPITAL LETTER DELTA
1F702 ββ π ββ ALCHEMICAL SYMBOL FOR FIRE
WHICH ONE OF THE CLASS NAMES IS VALID? (4)
class π
end
class π
end
$ uniscribe "π
π
"
1F146 ββ π
ββ SQUARED LATIN CAPITAL LETTER W
1F14F ββ π
ββ SQUARED WC
WHICH ONE OF THE CLASS NAMES IS VALID? (5)
class π‘
end
class π²
end
$ uniscribe "π‘π²"
1F853 ββ π‘ ββ DOWNWARDS SANS-SERIF ARROW
10C84 ββ π² ββ OLD HUNGARIAN CAPITAL LETTER EC