Skip to content

Instantly share code, notes, and snippets.

@reu
Created October 22, 2010 20:55
Show Gist options
  • Save reu/641354 to your computer and use it in GitHub Desktop.
Save reu/641354 to your computer and use it in GitHub Desktop.
lol.rb
def get(name, type = :string)
parameter = name.is_a?(Array) ? self.key_chain(*name) : self[name]
if !parameter.blank?
case type
when :string then parameter.to_s
when :hash, :collection then parameter
when :csv then parameter.split(',').map(&:strip)
when :integer then Integer(parameter)
when :float then Float(parameter)
when :boolean then ['true', 'yes', '1'].include?(parameter.downcase)
when :date, :datetime then parameter.to_local_datetime
end
elsif [:collection, :csv].include?(type)
[]
elsif type == :hash
{}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment