I'm looking for a way to add properties to my already defined class at runtime, or better:
class Client
attr_accessor :login, :password
def initialize args = {}
self.login = args[:login]
self.password = args[:password]
end
end
But then, I have this hash
{:swift_bic=>"XXXX", :account_name=>"XXXX", :id=>"123", :iban=>"XXXX"}
and I want this hash to become part of my client instance like
client = Client.new :login => 'ludicco', :password => 'xxxxx'
then with a miraculous magic
client @@%$%PLIM!!! {:swift_bic=>"XXXX", :account_name=>"XXXX", :id=>"123", :iban=>"XXXX"}
I would be able to access
client.swift_bic => 'XXXX'
client.account_name => 'XXXX'
client.id => 123
and I also would like to maintain a proper object structure like:
Client.new(:login => 'ludicco', :password => 'xxxxx').inspect
#<Client:0x1033c4818 @password='xxxxx', @login='ludicco'>
after the magic
client.inspect
#<Client:0x1033c4818 @password='xxxxx', @login='ludicco', @swift_bic='XXXX', @account_name='XXXX' @id => '123', @iban => 'XXXX'>
which would give me a very nice and well formatted json after that
Is it possible at all?
I'm getting this hash from a webservice, so I wouldn't know if theres a new property in there, and then I would have to update my app each time they perform an upgrade on their service. So, I'm sort of trying to avoid this :/
Thanks chaps.
:)