-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1072 lines (691 loc) · 42.5 KB
/
index.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Coding in an absurd reality</title>
<meta name="author" content="Ivo Wever">
<meta name="description" content="Enlightenment, science, democracy and equal opportunity are still the
true rebels, reigning for just a few generations (and still
imperfectly) in one …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://Confusion.github.com/">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="/javascripts/ender.js"></script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<link href="/atom.xml" rel="alternate" title="Coding in an absurd reality" type="application/atom+xml">
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
</head>
<body >
<header role="banner"><hgroup>
<h1><a href="/">Coding in an absurd reality</a></h1>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:Confusion.github.com" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div class="blog-index">
<article>
<header>
<h1 class="entry-title"><a href="/blog/2011/02/17/we-still-have-a-long-way-to-go/">We Still Have a Long Way to Go</a></h1>
<p class="meta">
<time datetime="2011-02-17T00:00:00+01:00" pubdate data-updated="true">Feb 17<span>th</span>, 2011</time>
| <a href="/blog/2011/02/17/we-still-have-a-long-way-to-go/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><blockquote><p>Enlightenment, science, democracy and equal opportunity are still the
true rebels, reigning for just a few generations (and still
imperfectly) in one or two corners of the Earth, after elite chiefs,
romantic bards and magicians dominated our ancestors for maybe half a
million years.</p></blockquote>
<p>— David Brin, in <a href="http://dir.salon.com/story/ent/feature/2002/12/17/tolkien_brin/print.html">J.R.R. Tolkien — enemy of progress</a></p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2010/08/05/identifying-your-ruby-implementation-at-runtime/">Identifying Your Ruby Implementation at Runtime</a></h1>
<p class="meta">
<time datetime="2010-08-05T00:00:00+02:00" pubdate data-updated="true">Aug 5<span>th</span>, 2010</time>
| <a href="/blog/2010/08/05/identifying-your-ruby-implementation-at-runtime/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>There are a number of global variables available to determine, at runtime,
which Ruby implementation you are using. You can find most of these in
<code>Object.constants</code> and the most interesting ones are:</p>
<ul>
<li>RUBY_ENGINE,</li>
<li>RUBY_PLATFORM,</li>
<li>RUBY_VERSION and</li>
<li>PLATFORM</li>
</ul>
<p>Why would you want to know this? For instance to be able to load a Java library
when our code is running in JRuby, but fallback to some other library when we
are running in MRI or Rubinius. In my current use case: to run most specs in
MRI, which starts way faster than JRuby. Loading of Java-specific code is
surrounded by:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'> <span class="k">if</span> <span class="no">RUBY_ENGINE</span> <span class="o">==</span> <span class="n">jruby</span>
</span><span class='line'> <span class="c1"># Load jars and stuff</span>
</span><span class='line'> <span class="k">else</span>
</span><span class='line'> <span class="n">logger</span><span class="o">.</span><span class="n">warn</span> <span class="s2">"Running in stubbed mode: only useful for specs that</span>
</span><span class='line'><span class="s2"> dont exercise the actual database connection."</span>
</span><span class='line'> <span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2010/08/01/ruby-has-only-one-kind-of-method-and-one-kind-of-method-container/">Ruby Has Only One Kind of Method and One Kind of Method Container</a></h1>
<p class="meta">
<time datetime="2010-08-01T00:00:00+02:00" pubdate data-updated="true">Aug 1<span>st</span>, 2010</time>
| <a href="/blog/2010/08/01/ruby-has-only-one-kind-of-method-and-one-kind-of-method-container/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>While learning Ruby, I found the talk of classes, modules, eigenclasses (also
known as singleton classes or metaclasses), instance methods, class methods and
singleton methods (also known as eigenmethods) pretty confusing. Fortunately,
when you put everything together<sup>[1]</sup>, it turns out to be very simple: Ruby has
only one kind of methods, which are instance methods of modules. The methods
that are accessible to an object, are the instance methods of its eigenclass
and the superclasses of the eigenclass.</p>
<p>If you’re thinking “no, Ruby also has class methods or singleton methods”: as
Ola Bini shows in <a href="http://ola-bini.blogspot.com/2006/09/ruby-singleton-class.html">his article on singleton classes</a>:
defining a class method or singleton method is identical to defining an instance
method on its eigenclass. Now if you define the method using either syntax, then
where does this method actually live? Both:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="no">C1</span><span class="o">.</span><span class="n">singleton_methods</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># and</span>
</span><span class='line'>
</span><span class='line'><span class="p">(</span><span class="k">class</span> <span class="o"><<</span> <span class="no">C1</span><span class="p">;</span> <span class="nb">self</span><span class="p">;</span> <span class="k">end</span><span class="p">)</span><span class="o">.</span><span class="n">instance_methods</span>
</span></code></pre></td></tr></table></div></figure>
<p>will report the method, but of course only one instance of this method exists.
The <a href="http://rubini.us/">Rubinius</a> implementation of Ruby reflects this:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">def</span> <span class="nf">singleton_methods</span><span class="p">(</span><span class="n">all</span><span class="o">=</span><span class="kp">true</span><span class="p">)</span>
</span><span class='line'> <span class="n">mt</span> <span class="o">=</span> <span class="no">Rubinius</span><span class="o">.</span><span class="n">object_metaclass</span><span class="p">(</span><span class="nb">self</span><span class="p">)</span><span class="o">.</span><span class="n">method_table</span>
</span><span class='line'> <span class="nb">methods</span> <span class="o">=</span> <span class="p">(</span><span class="n">all</span> <span class="p">?</span> <span class="n">mt</span><span class="o">.</span><span class="n">names</span> <span class="p">:</span> <span class="n">mt</span><span class="o">.</span><span class="n">public_names</span> <span class="o">+</span> <span class="n">mt</span><span class="o">.</span><span class="n">protected_names</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="no">Rubinius</span><span class="o">.</span><span class="n">convert_to_names</span> <span class="nb">methods</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>When you ask for the singleton methods of a class, you get the methods (the
method_table) of its metaclass.</p>
<p>The consequence of this is that it gets much easier to reason about the
behavior of <a href="http://ruby-doc.org/core/classes/Object.html#M000335">extend</a> and
<a href="http://ruby-doc.org/core/classes/Module.html#M001638">include</a>: extending a
module is equivalent to adding its instance methods to the instance methods of
the eigenclass of the extending module. That you can access them via
<code>ExtendingModule.module_instance_method</code> is merely syntactical sugar.</p>
<p>Including a module is equivalent to adding the module’s instance methods to the
instance methods of the class. The instance methods of a class are accessible
to instances of the class, which is how an instance can have access to the
included module’s instance methods.</p>
<p>Examples:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">module</span> <span class="nn">M1</span>
</span><span class='line'> <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">module_singleton_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.module_singleton_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'> <span class="k">def</span> <span class="nf">module_instance_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.module_instance_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'> <span class="k">class</span> <span class="o"><<</span> <span class="nb">self</span>
</span><span class='line'> <span class="k">def</span> <span class="nf">module_eigenclass_instance_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.module_eigenclass_instance_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'> <span class="k">if</span> <span class="o">!</span><span class="nb">instance_methods</span><span class="o">.</span><span class="n">include?</span> <span class="n">module_singleton_method</span>
</span><span class='line'> <span class="k">raise</span> <span class="no">StandardError</span><span class="p">,</span> <span class="s2">"This wont happen."</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">module</span> <span class="nn">M2</span><span class="p">;</span> <span class="kp">extend</span> <span class="no">M1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">module</span> <span class="nn">M3</span><span class="p">;</span> <span class="kp">include</span> <span class="no">M1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">module</span> <span class="nn">M4</span><span class="p">;</span> <span class="kp">extend</span> <span class="no">M3</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># Everything that raises an Error is commented</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># You cant subclass a module:</span>
</span><span class='line'><span class="c1"># module M5 < M1; end</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># You cant instantiate modules: Module doesnt have a new method.</span>
</span><span class='line'><span class="c1"># M1.new</span>
</span><span class='line'>
</span><span class='line'><span class="nb">puts</span> <span class="s2">"Accessing methods through an instance of Module"</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">M1</span><span class="o">.</span><span class="n">module_singleton_method</span>
</span><span class='line'><span class="c1"># puts M1.module_instance_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">M1</span><span class="o">.</span><span class="n">module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts M2.module_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">M2</span><span class="o">.</span><span class="n">module_instance_method</span>
</span><span class='line'><span class="c1"># puts M2.module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts M3.module_singleton_method</span>
</span><span class='line'><span class="c1"># puts M3.module_instance_method</span>
</span><span class='line'><span class="c1"># puts M3.module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts M4.module_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">M4</span><span class="o">.</span><span class="n">module_instance_method</span>
</span><span class='line'><span class="c1"># puts M4.module_eigenclass_instance_method</span>
</span></code></pre></td></tr></table></div></figure>
<p>What can we conclude from this?</p>
<ul>
<li>You cannot access a module’s instance methods, except by extending the
module. When you extend a module, its instance methods are added as
instance methods to the eigenclass of the extending module. In the
example, M1’s instance methods become instance methods of M2’s
eigenclass.</li>
<li>Including a module into another module makes the instance methods of the
included module available as instance methods in the including module.
This may seem pointless, because you still can’t access them, but
subsequently extending the including module also makes the included
module’s methods available to the extending module. In the example, M1’s
instance methods were added to M3’s and through the extend they became to
M4.</li>
<li>Defining a singleton method on a module has exactly the same result as
defining an instance method on a module’s eigenclass. Neither extending
nor including the module will make the instance methods of its eigenclass
available to the extending or including module.</li>
<li>You can only inherit from a class, not from a module.</li>
</ul>
<p>For classes, it’s pretty much the same:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
<span class='line-number'>50</span>
<span class='line-number'>51</span>
<span class='line-number'>52</span>
<span class='line-number'>53</span>
<span class='line-number'>54</span>
<span class='line-number'>55</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">class</span> <span class="nc">C1</span>
</span><span class='line'> <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">class_singleton_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.class_singleton_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'> <span class="k">def</span> <span class="nf">class_instance_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.class_instance_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'> <span class="k">class</span> <span class="o"><<</span> <span class="nb">self</span>
</span><span class='line'> <span class="k">def</span> <span class="nf">class_eigenclass_instance_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.module_eigenclass_instance_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'> <span class="k">if</span> <span class="o">!</span><span class="nb">instance_methods</span><span class="o">.</span><span class="n">include?</span> <span class="n">class_singleton_method</span>
</span><span class='line'> <span class="k">raise</span> <span class="no">StandardError</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">C2</span> <span class="o"><</span> <span class="no">C1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">C3</span><span class="p">;</span> <span class="kp">extend</span> <span class="no">M1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">C4</span><span class="p">;</span> <span class="kp">include</span> <span class="no">M1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># class C5; extend C1; end</span>
</span><span class='line'><span class="c1"># class C6; include C1; end</span>
</span><span class='line'>
</span><span class='line'><span class="nb">puts</span> <span class="s2">"Accessing methods through an instance of Class"</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C1</span><span class="o">.</span><span class="n">class_singleton_method</span>
</span><span class='line'><span class="c1"># puts C1.class_instance_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C1</span><span class="o">.</span><span class="n">class_eigenclass_instance_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C2</span><span class="o">.</span><span class="n">class_singleton_method</span>
</span><span class='line'><span class="c1"># puts C2.class_instance_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C2</span><span class="o">.</span><span class="n">class_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C3.module_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C3</span><span class="o">.</span><span class="n">module_instance_method</span>
</span><span class='line'><span class="c1"># puts C3.module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C4.module_singleton_method</span>
</span><span class='line'><span class="c1"># puts C4.module_instance_method</span>
</span><span class='line'><span class="c1"># puts C4.module_eigenclass_instance_method</span>
</span><span class='line'>
</span><span class='line'><span class="nb">puts</span> <span class="s2">"Accessing methods through a class instance"</span>
</span><span class='line'><span class="c1"># puts C1.new.class_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C1</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">class_instance_method</span>
</span><span class='line'><span class="c1"># puts C1.new.class_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C2.new.class_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C2</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">class_instance_method</span>
</span><span class='line'><span class="c1"># puts C2.new.class_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C3.new.module_singleton_method</span>
</span><span class='line'><span class="c1"># puts C3.new.module_instance_method</span>
</span><span class='line'><span class="c1"># puts C3.new.module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C4.new.module_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C4</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">module_instance_method</span>
</span><span class='line'><span class="c1"># puts C4.new.module_eigenclass_instance_method</span>
</span></code></pre></td></tr></table></div></figure>
<p>From this we can conclude:</p>
<ul>
<li>Instance methods of a class are accessible to each instance of the class.
Each instance has it’s own unique eigenclass, but when a method isn’t
found there, the next stop is the superclass of the eigenclass, which is
the object representing the same class we usually consider the class of
the instance.</li>
<li>You can only extend or include modules, not classes.</li>
<li>When a class extends a module, the module’s instance methods are added to
the instance methods of the class’s eigenclass. Since classes are
modules, this is exactly as expected.</li>
<li>Including a module into a class makes the module’s instance methods
available to all instances of the class.</li>
</ul>
<hr />
<p><sup>[1]</sup> With a little help from the excellent:
<a href="http://pragprog.com/titles/ppmetr/metaprogramming-ruby">Metaprogramming Ruby</a> by Paolo Perrotta</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2010/07/08/drowning-doesnt-look-like-drowning/">Drowning Doesn’t Look Like Drowning</a></h1>
<p class="meta">
<time datetime="2010-07-08T00:00:00+02:00" pubdate data-updated="true">Jul 8<span>th</span>, 2010</time>
| <a href="/blog/2010/07/08/drowning-doesnt-look-like-drowning/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p><a href="http://mariovittone.com/2010/05/154/">Something everyone should know</a> when
someone is drowning, it doesn’t look
the way it is portrayed in movies. Especially children are known
to drown within reach of others, because everyone, even their parents, are
unaware something is wrong.</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2010/02/26/tipsandtrickstextbasedlinuxinstall---dropbox-wiki/">TipsAndTricks/TextBasedLinuxInstall - Dropbox Wiki</a></h1>
<p class="meta">
<time datetime="2010-02-26T00:00:00+01:00" pubdate data-updated="true">Feb 26<span>th</span>, 2010</time>
| <a href="/blog/2010/02/26/tipsandtrickstextbasedlinuxinstall---dropbox-wiki/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>Wow, there’s actually <a href="http://wiki.dropbox.com/TipsAndTricks/TextBasedLinuxInstall">a Linux CLI version of DropBox</a>.
Amazing!</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2010/02/13/a-few-billion-lines-of-code-later/">A Few Billion Lines of Code Later: Using Static Analysis to Find Bugs in the Real World</a></h1>
<p class="meta">
<time datetime="2010-02-13T00:00:00+01:00" pubdate data-updated="true">Feb 13<span>th</span>, 2010</time>
| <a href="/blog/2010/02/13/a-few-billion-lines-of-code-later/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p><a href="http://cacm.acm.org/magazines/2010/2/69354-a-few-billion-lines-of-code-later/fulltext">A very interesting story</a>
about the practical problems the guys that developed <a href="http://www.coverity.com/">Coverity’s</a>
static analysis tool encountered. Shows the difference between
academic theory and practice, but applies just as much to any theory developers
usually have about a software application, before actual customers start using
it.</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2010/02/12/schneier-on-security-man-in-the-middle-attack-against-chip-and-pin/">Schneier on Security: Man-in-the-Middle Attack Against Chip and PIN</a></h1>
<p class="meta">
<time datetime="2010-02-12T00:00:00+01:00" pubdate data-updated="true">Feb 12<span>th</span>, 2010</time>
| <a href="/blog/2010/02/12/schneier-on-security-man-in-the-middle-attack-against-chip-and-pin/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p><a href="http://www.schneier.com/blog/archives/2010/02/man-in-the-midd_1.html">As Bruce says</a>:</p>
<blockquote><p>This is big.</p></blockquote>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2010/02/10/the-twitter-engineering-blog-hello-world/">The Twitter Engineering Blog: Hello World</a></h1>
<p class="meta">
<time datetime="2010-02-10T00:00:00+01:00" pubdate data-updated="true">Feb 10<span>th</span>, 2010</time>
| <a href="/blog/2010/02/10/the-twitter-engineering-blog-hello-world/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p><a href="http://engineering.twitter.com/2010/02/hello-world.html">Funky animation</a> that
shows how the code in the Twitter repository grew the past few years.</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2010/02/03/lisp-evangelists-that-miss-the-point-about-syntax/">Lisp Evangelists That Miss the Point About Syntax</a></h1>
<p class="meta">
<time datetime="2010-02-03T00:00:00+01:00" pubdate data-updated="true">Feb 3<span>rd</span>, 2010</time>
| <a href="/blog/2010/02/03/lisp-evangelists-that-miss-the-point-about-syntax/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>People that promote Lisp usually tout the fact that you can construct new
syntax as one of its powerful features. However, when it comes to any other
programming language, a number of these people will say that the language is
wrong, because it has too much syntax. As any syntax seems to be too much, the
complaint about the syntax is actually a red herring. The real complaint is:
this language isn’t Lisp and I can’t ‘drop down’ to a lower level to adjust the
syntax to my needs.</p>
<p>As many people in <a href="http://news.ycombinator.com/item?id=1097911">this thread</a>,
which inspired this post, point out: the
ability to create syntax is powerful, exactly because syntax increases the
usability of the language for your specific purpose. So why not create syntax
that catches 99% of the cases for which you intend the language to be used and
abolish the ability to create further syntax? The ability to create syntax
comes at a cost and the existence of so many other programming languages shows
one thing very clearly: not everyone is willing to pay that cost. Why can’t we
live with that fact, use Lisp when we need it or want to and
stop criticizing other languages for not being Lisp?</p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2010/01/20/writers-and-editors-dont-make-me-feel-stupid/">Writers and Editors: Don’t Make Me Feel Stupid!</a></h1>
<p class="meta">
<time datetime="2010-01-20T00:00:00+01:00" pubdate data-updated="true">Jan 20<span>th</span>, 2010</time>
| <a href="/blog/2010/01/20/writers-and-editors-dont-make-me-feel-stupid/#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>Imagine you don’t know what a <a href="http://en.wikipedia.org/wiki/Web_service">web_service</a> is, but you’ve heard someone talking
about them and you are interested in knowing more about them. You click the
link in the previous sentence and are told</p>
<pre><code> Web services today are frequently just Application Programming
Interfaces (API) or web APIs that can be accessed over a network,
such as the Internet, and executed on a remote system hosting the
requested services.
</code></pre>
<p>That didn’t make any sense to you, but you continued reading and made it to</p>
<pre><code> The W3C defines a “web service” as “a software system designed to
support interoperable machine-to-machine interaction over a network.
</code></pre>
<p>which started to make a bit of sense. However, as you weren’t particularly
enlightened yet, you enter ‘What_is_a_webservice’ into Google and read other
<a href="http://www.google.com/search?ie=UTF-8&q=what+is+a+web+service">‘explanations’</a> like the one from <a href="http://www.webopedia.com/TERM/W/Web_Services.html">Webopedia</a>:</p>
<pre><code> The term Web services describes a standardized way of integrating
Web-based applications using the XML, SOAP, WSDL and UDDI open
standards over an Internet protocol backbone. XML is used to tag the
data, SOAP is used to transfer the data, WSDL is used for describing
the services available and UDDI is used for listing what services are
available. Used primarily as a means for businesses to communicate
with each other and with clients, Web services allow organizations to
communicate data without intimate knowledge of each other’s IT
systems behind the firewall.
</code></pre>
<p>There’s not a doubt on my mind that most people are now left feeling stupid and
confused. This is a very bad thing, because it discourages people from
learning: if it is impossible to find a decent introduction to a subject,
surely it’s either too hard or too obscure?
There are several possible explanations for why these introductions are so bad:</p>
<ul>
<li>Perhaps it is simply too hard to introduce a subject using common English
terms?</li>
<li>Perhaps the authors have an advanced understanding of the subject, but
not of writing for a general audience?</li>
<li>Perhaps they suffer from the disease of overuse of jargon to which people
in every profession fall prey?</li>
<li>Perhaps they feel the quality of an article suffers when a web service
would be introduced in terms a layman could follow, like
<pre><code>A web service is a service offered by a piece of software that allows
one computer to receive and answer requests for information from
other computers over a network
</code></pre></li>
</ul>
<p>I’m not sure which of these reasons is dominant, but even if all of them hold
for the authors: surely there is at least one editor that realizes it should be
thumbed down and can explain how and why?</p>
<p>What motivated me to write this article was the fact that, for the first time,
I had to use WS-Addressing and WS-Security in a web service client and the
first question that came to mind was: “why do we need these”? After figuring
that out, I concluded that the explanations on Wikipedia and other high-ranking
search results really didn’t give me the answers I was looking for.</p>
<p>Firstly they suffered from the problems described in the beginning of this post, but
secondly: the explanations never went into the ‘why’ of these things. They all
just explained the ‘what’ and the ‘how’. This is what the Wikipedia
introduction on WS-Addressing currently says:</p>
<pre><code> WS-Addressing or Web Services Addressing is a specification of
transport-neutral mechanisms that allow web services to communicate
addressing information. It essentially consists of two parts: a
structure for communicating a reference to a Web service endpoint,
and a set of Message Addressing Properties which associate addressing
information with a particular message.
</code></pre>
<p>Now I don’t like feeling stupid and I don’t like having to think longer than is
strictly necessary to understand something and this causes both. Why wouldn’t
something like the following do?</p>
<pre><code> The motivation for WS-Addressing is that you want to allow clients to
invoke a web service using address A, while the web service itself
lives at address B. This allows you to, for instance, use address A
as a front door to web services at addresses B, C, D and E, while
having the software at address A perform routing, validation,
authentication, etc. for all these other web services. It also allows
you more freedom in your web service addresses, because they don’t
need to be URL’s that are reachable over the network: only address A
needs to be ‘real’.
</code></pre>
<p>Secondly, a FAQ or the like should answer the obvious question: can’t you solve
this in some other way?</p>
<pre><code> Of course you can come up with your own scheme to obtain the same
goal, but one downside to that is that the software at address A
would have to be able to deal with different homegrown
implementations of the same general principle, if it were to allow
access to web services of different origins. Another downside is that
you may initially overlook functionality, that proves harder to ‘tack
on’ later. That’s why Microsoft, IBM, Sun, BEA and SAP, under the
auspices of the W3C, came up with a single standard, which contains
specifications for all scenarios they could think of.
</code></pre>
</div>
</article>
<div class="pagination">
<a href="/blog/archives">Blog Archives</a>
</div>
</div>
<aside class="sidebar">
<section>
<h1>About</h1>
<p>A programmer by profession, a physicist by training, a philosopher by nature</p>
</section>
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/blog/2011/02/17/we-still-have-a-long-way-to-go/">We still have a long way to go</a>
</li>
<li class="post">
<a href="/blog/2010/08/05/identifying-your-ruby-implementation-at-runtime/">Identifying your Ruby implementation at runtime</a>
</li>
<li class="post">
<a href="/blog/2010/08/01/ruby-has-only-one-kind-of-method-and-one-kind-of-method-container/">Ruby has only one kind of method and one kind of method container</a>
</li>
<li class="post">
<a href="/blog/2010/07/08/drowning-doesnt-look-like-drowning/">Drowning Doesn’t Look Like Drowning</a>
</li>
<li class="post">
<a href="/blog/2010/02/26/tipsandtrickstextbasedlinuxinstall---dropbox-wiki/">TipsAndTricks/TextBasedLinuxInstall - Dropbox Wiki</a>
</li>
</ul>
</section>
<section>
<h1>Latest Tweets</h1>
<ul id="tweets">
<li class="loading">Status updating…</li>
</ul>
<script type="text/javascript">
$.domReady(function(){
getTwitterFeed("Confusionist", 4, false);
});
</script>
<script src="/javascripts/twitter.js" type="text/javascript"> </script>
<a href="http://twitter.com/Confusionist" class="twitter-follow-button" data-show-count="false">Follow @Confusionist</a>
</section>
<section>
<h1>GitHub Repos</h1>
<ul id="gh_repos">
<li class="loading">Status updating…</li>
</ul>
<a href="https://github.com/Confusion">@Confusion</a> on GitHub
<script type="text/javascript">