Answer the question
In order to leave comments, you need to log in
What is the best way to work with configurations in Ruby?
Let's say we have some configuration structure (taken from YAML, JSON, XML, or simply as a Hash):
↓
configuration = {
gmail: {
username: '[email protected]',
password: 'pa$$word',
host: 'imap.gmail.com',
ssl: true,
port: 993
},
ftp: {
username: '[email protected]',
password: 'pa$$word',
host: 'imap.gmail.com',
ssl: true,
port: 42
}
}
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]
Answer the question
In order to leave comments, you need to log in
Can be made easier
mail = Mail.new configuration[:gmail]
ftp = FTP.new configuration[:ftp]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question