--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

The problem: a Person should be an OpenStruct-like Entity, with the
Entity being taking care of the Person OpenStruct-ness and persistence
(say, for starters, the Person being added to a pool of Entities).

Tentative approach with inheritance:



require 'ostruct'

class Entity < OpenStruct
  def initialize *args
    puts 'Entity#initialize'
    super
    puts "adding #{self} to pool"
  end
end

class Person < Entity
  def initialize *args
    puts 'Person#initialize'
    super
  end
end

Person.new name_prefix: 'Dr', given_names: ['Horace'], surname: 'Worblehat'



Result:

Person#initialize
Entity#initialize
adding #<Person name_prefix="Dr", given_names=["Horace"], surname="Worblehat"> to pool



The problem: how about making Entity a module so not to
require Person to inherit from it. Something like the below:



require 'ostruct'

module Entity
  def initialize *args
    puts 'Entity#initialize'
    super
    puts "adding #{self} to pool"
  end
end

class Person < OpenStruct
  include Entity
  def initialize *args
    puts 'Person#initialize'
    super
  end
end

Person.new name_prefix: 'Dr', given_names: ['Horace'], surname: 'Worblehat'



Result:

Person#initialize
Entity#initialize
adding #<Person name_prefix="Dr", given_names=["Horace"], surname="Worblehat"> to pool



The real problem: how to move the OpenStruct-ness of Entities away from
Person and into the Entity? You can include/extend Entity into/with
OpenStruct (because OpenStruct is not a module) and you can make
Entity inherit from OpenStruct (because Entity is a module).

I fine with, say, any Entity.new + Entity.included
(not-really-)magic required or some such, I just can
seem to be able to put my finger on the needed wiring:)

(A cherry on the top would be if Person#initialize did not
have to remember to call super; I want Person to be as simple
as possible and offload as much as possible to Entity.)

Piotr Szotkowski
-- 
°∆The Ruby community should proceed with all deliberate
speed towards ISO standardization of the language.°«
°∆Yeah, look what it did to Forth.°«
°∆Don°«t just say it, show it: <http://vividpicture.com/aleks/atari/forth.jpg>°«
            [M. Edward (Ed) Borasky, Matt Lawrence, Gregory Brown, ruby-talk]




--ikeVEW9yuYc//A+q
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk0j/J8ACgkQi/mCfdEo8Uqb2wCfV/Dm2LPUCxAS5W07hd/z9D+s
Q1MAnjqoeef0DFxVLa9Mbk19Qotx2JOK
Ql
-----END PGP SIGNATURE-----

--ikeVEW9yuYc//A+q--