Re: Need help understanding metaclassing



Robert Dober wrote:
On 10/25/07, Chris Czub <chris.czub@xxxxxxxxx> wrote:
Why can't I use the attribute accessor? Rather - I understand why I
can't, because it was created in the User class rather than the
DefaultUser class, but how can I get access to it?
--
Posted via http://www.ruby-forum.com/.



class User
@users = {}
class << self
attr_reader :users
end
def initialize name
email = nil
loop do
email = "#{name}@#{rand 1000}"
break unless self.class.users[ email ]
end
self.class.users[ email ] = self
....

is this what you want?
R.

I don't really want to define it in the User class, because it might not
belong to a particular user... maybe I am not making sense.

I am writing a testing application for many web sites that require user
registrations. Each website requires similar users, but different ones
might have additional fields required of a user, so my idea is to create
a metaclass of user for each user configuration a website might require.
So, for a web site based in the UK, the metaclass looks like this:

class UKUser < User
attribs :address3, :i_own_or_work_for_a_small,
:my_small_business_has_its, :yes_please_send_me_the_mi, :postal
first_name( "John" )
last_name( "Doe" )
email( "john.doe#{rand(100)}@abc.com" )
address1( "1 Sunshine Parkway" )
address2( "" )
address3( "" )
city( "London" )
postal( "EH15 2JJ" )
gender( "male" )
phone( "(555)123-4567" )
age( "18-25" )
my_small_business_has_its( "no" )
i_own_or_work_for_a_small( "no" )
yes_please_send_me_the_mi( "no" )
end





So I am able to say

user = UKUser.new
user.address3("Apartment 12")
user.my_small_business_has_its("yes")

However, I cannot do this:

user.email("bob.smith@xxxxxxx")


Any ideas?
--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Re: Slow Downloads
    ... The link I provided was for Broadband Reports, not Cox. ... comfortable switching from IE to another browser. ... Are there any Web sites that cause no problems at all? ... America's website takes a long time to load. ...
    (microsoft.public.windowsxp.general)
  • Re: Visual Studio "New Project" or "New Website"
    ... that you can't do with a WebSite (providing you use "Publish WebSite, ... They're not available for web sites, ... cause your code to be compiled first, and can even compile or partially ... and I had been developing ASP.NET Web Applications ...
    (microsoft.public.vsnet.general)
  • Re: IIS 6.0 Unique ID generation
    ... but I don't think it needs the ID to create the website. ... > I am hosting multiple web sites on a w2k3 server and want to create web ... > use and create the new site with that ID but I know MMC uses an algorithm ... IIS 6.0 assigns unique IDs based on the specified ...
    (microsoft.public.inetserver.iis)
  • Re: browser warning for Web Standards Compliance
    ... Cannot Connect to Secure Websites ... completing Internet transactions - or if you have started seeing the message ... "HTTP 500 internal server error" when trying to visit secure Web sites - ... > When trying to reach my bank website, ...
    (microsoft.public.windows.inetexplorer.ie6.browser)