@@ -51,8 +51,263 @@ <h1>Ruby 2.0</h1>
51
51
< a href ="http://secretsaucepartners.com "> < img src ="assets/ssp.png " width ="64 " height ="64 " /> </ a >
52
52
</ section >
53
53
54
- </ div >
54
+ < section >
55
+ < h1 > Timeline</ h1 >
56
+ < ul >
57
+ < li > Ruby 1.8: 2003 August</ li >
58
+ < li > Ruby 1.9: 2007 December</ li >
59
+ < li > Ruby 2.0.0-p0: 2013 February 24</ li >
60
+ < li > Ruby 2.0.0-p195: 2013 May 14</ li >
61
+ < li > Ruby 2.0.0-p247: 2013 June 27</ li >
62
+ < li strong style ="color:#bada55 "> Ruby 2.0.0-p353: 2013 November 22</ li >
63
+ < li > Ruby 2.1.0-p0: 2013 December 25</ li >
64
+ </ ul >
65
+ </ section >
66
+
67
+ < section >
68
+ < h1 > Install</ h1 >
69
+ < h3 > rvm</ h3 >
70
+ < pre >
71
+ < code >
72
+ rvm install ruby-2.0.0
73
+ </ code >
74
+ </ pre >
75
+ < h3 > rbenv</ h3 >
76
+ < pre >
77
+ < code >
78
+ rbenv install 2.0.0-p353
79
+ </ code >
80
+ </ pre >
81
+ </ section >
82
+
83
+ < section >
84
+ < h1 > Compatibility</ h1 >
85
+ < img src ="assets/chill.png " />
86
+ </ section >
87
+
88
+ < section >
89
+ < h1 > Deep changes</ h1 >
90
+ </ section >
91
+
92
+ < section >
93
+ < h3 > Bitmap garbage collection</ h3 >
94
+ </ section >
95
+
96
+ < section >
97
+ < h3 > Backwards compatible with 1.9</ h3 >
98
+ </ section >
99
+
100
+ < section >
101
+ < h3 > require() speed improvements</ h3 >
102
+ </ section >
103
+
104
+ < section >
105
+ < h1 > Big changes</ h1 >
106
+ </ section >
107
+
108
+ < section >
109
+ < h1 > Keyword arguments</ h1 >
110
+ < h3 > today</ h3 >
111
+ < pre >
112
+ < code >
113
+ def foo(foo: 'bar', baz: 'qux', **rest)
114
+ # TODO
115
+ end
116
+
117
+ foo(baz: 'qux', foo: 'frob')
118
+ </ code >
119
+ </ pre >
120
+ < h3 > future</ h3 >
121
+ < pre >
122
+ < code >
123
+ def foo(optional: 'default', required:)
124
+ end
125
+ </ code >
126
+ </ pre >
127
+ </ section >
128
+
129
+ < section >
130
+ < h1 > Prepend</ h1 >
131
+ < pre >
132
+ < code >
133
+ module Foo
134
+ def somehing; end
135
+ end
136
+
137
+ class MyClass
138
+ prepend Foo
139
+ end
140
+
141
+ MyClass.ancestors # => [Foo, MyClass, Object...]
142
+ </ code >
143
+ </ pre >
144
+ < small > No more < span style ="color:#bada55 "> alias_method_chain</ span > </ small >
145
+ </ section >
146
+
147
+ < section >
148
+ < h1 > Lazy enumerators</ h1 >
149
+ < pre >
150
+ < code >
151
+ to_infinity = (0..Float::Infinity)
55
152
153
+ beyond =to_infinity.lazy.select do |n|
154
+ num % 42 == 0
155
+ end
156
+
157
+ 100.times do { |n| puts beyond.next }
158
+ </ code >
159
+ </ pre >
160
+ < h3 > Enumerator#size</ h3 >
161
+ < pre >
162
+ < code >
163
+ (1..100).to_a.permutation(4).size # => 94109400
164
+
165
+ enum = Enumerator.new(3) do |yielder| ...; end
166
+
167
+ def square_times(num)
168
+ return to_enum(:square_times) {num ** 2} unless block_given?
169
+ (num ** 2).times do |i|
170
+ yield i
171
+ end
172
+ end
173
+ </ code >
174
+ </ pre >
175
+ </ section >
176
+
177
+ < section >
178
+ < h1 > Refinements</ h1 >
179
+ < pre >
180
+ < code >
181
+ module Palindrome
182
+ refine String do
183
+ def palindrome?
184
+ self == self.reverse
185
+ end
186
+ end
187
+ end
188
+
189
+ using Palindrome # Monkey patchnow active for context
190
+
191
+ "saippuakivikauppias".palindrome? # => true
192
+ </ code >
193
+ </ pre >
194
+ </ section >
195
+
196
+ < section >
197
+ < h1 > Small changes</ h1 >
198
+ </ section >
199
+
200
+ < section >
201
+ < h1 > Symbol array literal</ h1 >
202
+ < pre >
203
+ < code >
204
+ %i[foo bar baz] # => [:foo, :bar, :baz]
205
+
206
+ %I[#{1 + 1}x #{2 + 2}x] #=> [:"2x", :"4x"]
207
+ </ code >
208
+ </ pre >
209
+ </ section >
210
+
211
+ < section >
212
+ < h1 > Binary search</ h1 >
213
+ < pre >
214
+ < code >
215
+ haystack = (1..99999999)
216
+
217
+ haystack.bsearch do |needle|
218
+ needle == 12345
219
+ end
220
+
221
+ # => 12345
222
+ </ code >
223
+ </ pre >
224
+ </ section >
225
+
226
+ < section >
227
+ < h1 > UTF8 by default</ h1 >
228
+ < h3 > Ruby 1.9</ h3 >
229
+ < pre >
230
+ < code >
231
+ #!/usr/bin/env ruby1.9
232
+ #encoding: utf-8
233
+
234
+ puts "★"
235
+ </ code >
236
+ </ pre >
237
+ < h3 > Ruby 2.0</ h3 >
238
+ < pre >
239
+ < code >
240
+ #!/usr/bin/env ruby-2.0
241
+
242
+ puts "★"
243
+ </ code >
244
+ </ pre >
245
+
246
+ </ section >
247
+
248
+ < section >
249
+ < h1 > File directory</ h1 >
250
+ < pre >
251
+ < code >
252
+ # Ruby 1.8
253
+ require File.dirname(__FILE__) + "/lib"
254
+ File.read(File.dirname(__FILE__) + "/.config")
255
+
256
+ # Ruby 1.9
257
+ require_relative 'lib'
258
+ File.read(File.dirname(__FILE__) + '/.config')
259
+
260
+ # Ruby 2.0
261
+ require_relative 'lib'
262
+ File.read(__dir__ + '/.config')
263
+ </ code >
264
+ </ pre >
265
+ </ section >
266
+
267
+ < section >
268
+ < h1 > to_h</ h1 >
269
+ < pre >
270
+ < code >
271
+ Car = Struct.new(:make, :model, :year) do
272
+ def build
273
+ #...
274
+ end
275
+ end
276
+ car = Car.new('Toyota', 'Prius', 2014)
277
+ car.to_h # => {:make=> "Toyota", :model=> "Prius", :year=> 2014}
278
+ nil.to_h # => {}
279
+ </ code >
280
+ </ pre >
281
+ < small >
282
+ < p > Implemented for:</ p >
283
+ < ul >
284
+ < li > nil</ li >
285
+ < li > Struct</ li >
286
+ < li > OpenStruct</ li >
287
+ < li style ="text-decoration:line-through "> Enumerable/Array</ li >
288
+ </ ul >
289
+ </ small >
290
+ </ section >
291
+
292
+ < section >
293
+ < h1 > ETC</ h1 >
294
+ < p >
295
+ < ul >
296
+ < li > Unused variables can start with _</ li >
297
+ < li > caller_locations</ li >
298
+ < li > const_get understands namespaces</ li >
299
+ < li > Rubygems Gemfile support</ li >
300
+ < li > RDoc markdown support</ li >
301
+ </ ul >
302
+ </ p >
303
+ < small > < a href ="http://globaldev.co.uk/2013/03/ruby-2-0-0-in-detail/ "> and many more...</ a > </ small >
304
+ </ section >
305
+
306
+ < section >
307
+ < h1 > Thanks!</ h1 >
308
+ < img src ="assets/great_gatsby.jpg " />
309
+ </ section >
310
+ </ div >
56
311
</ div >
57
312
58
313
< script src ="lib/js/head.min.js "> </ script >
0 commit comments