Created
November 13, 2008 16:50
-
-
Save cassiomarques/24493 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attr_names.each do |attr_name| | |
attr_name = attr_name.to_s | |
class_eval("def #{attr_name}; read_and_symbolize_attribute('#{attr_name}'); end") | |
class_eval("def #{attr_name}= (value); write_symbolized_attribute('#{attr_name}', value); end") | |
# Adicao de um novo metodo que retorna a respectiva string descritiva para cada symbol presente no hash passado | |
# para a opcao :in | |
# class User < ActiveRecord::Base | |
# symbolize :gender, :in => [:female, :male] | |
# symbolize :so, :in => { | |
# :windows => "Windows XP", | |
# :linux => "Linux", | |
# :mac => "Mac OS X" | |
# } | |
# end | |
# | |
# u = User.new(:so => :linux) | |
# puts u.so_str # => "Linux" | |
# | |
# TODO: Testar isso aqui... como rodar os testes?! | |
# | |
# Alteracao por Cassio Marques (12/11/2008) | |
class_eval("def #{attr_name}_str; self.class.get_#{attr_name}_values[read_and_symbolize_attribute('#{attr_name}')]; end") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment