Suppose we have a certain configuration structure (taken from YAML , JSON , XML or simply as a Hash ):
configuration = { gmail: { username: 'example@gmail.com', password: 'pa$$word', host: 'imap.gmail.com', ssl: true, port: 993 }, ftp: { username: 'example@gmail.com', password: 'pa$$word', host: 'imap.gmail.com', ssl: true, port: 42 } } Further, on the basis of this structure, we obtain data from it:
mail = Mail.new host: configuration[:gmail][:host], port: configuration[:gmail][:port], username: configuration[:gmail][:username], password: configuration[:gmail][:password], ssl: configuration[:gmail][:ssl] ftp = FTP.new host: configuration[:ftp][:host], port: configuration[:ftp][:port], username: configuration[:ftp][:username], password: configuration[:ftp][:password], ssl: configuration[:ftp][:ssl] Everything works, but the code itself is “poorly readable”. That is, it is of course understandable, but too much “dry” text, instead of the usual code for the programming language.
Share Best Practice , how to do and use configurations in Ruby .