title: Is it possible to extend an individual object in Smalltalk
body: <p>I'm doing research in Smalltalk reflection, and I was wondering if it was possible to extend an individual object like that would be possible for instance in Ruby. With this I mean a selector that only particular objects respond to.</p>
  
  <p>Here is some Ruby code that states what I mean.
  For clarification: in Ruby this open a virtual class for this object, and extends it with a new definition. The vital part here is that nothing changes to the class definition!</p>
  
  <pre><code>o = Object.new
  o.instance_eval {def foo;puts "foo";end}
  o.foo #=&gt; "foo"
  
  #however this will fail:
  m = Object.new
  m.foo #=&gt; NoMethod error
  </code></pre>
  
  <p>More specifically my question is whether this is possible in standard Squeak/Pharo or other smalltalk implementations, without adding substantial structures or code to allow this. So with other words with regular reflective features that exist in Smalltalk.</p>
  
  <p>As an example, it is possible to add methods, remove methods, compile new code into a class, change instance variables and just about anything, but I haven't found a way to extend a single object.</p>
  
  <pre><code>Test addInstVarNamed: #var.
  Test compile: 'var ^var'.
  t:= Test new.
  Test instVarNames.
  t instVarNamed: #var put: 666. 
  t var. #=&gt; 666
  </code></pre>
  
  <p><strong>If the answer is no, then explain why. I'm not looking for solving this problem but rather understanding why it isn't in smalltalk.</strong></p>