From: Sergey Sheypak Date: 2010-02-12T18:23:15+09:00 Subject: Re: String to symbol Robert Klemme wrote: > 2010/2/12 Sergey Sheypak : >> �def is_attr_allowed!(attr) > IMHO that method would rather be called ensure_attr_allowed - if you > call it is_... I would expect it to return a boolean. I've added "!" to show that it can throw exception (like in rails) > > Are you sure this is what you want? It seems you change the accessor > method for *all* instances to return the *same* value. I don't think > this is a good idea. I have a bean. Bean can accept certain fields in his constructor. List of certain fields is overriden in each subclass of DataBean. I read source (csv) file and try to construct bean using dats from source and my bean. > >> So I can use 'rails like intializers' >> >> As I read, :symbols are constants, they are immutable and have int >> representation. These facts help to spend less memory and resources. >> >> Do I have any opportunity to pass Strings into my initializers? > > Did you try it out with your code? Was there an issue, if so, which > one? > Code works fine. I've just added to config.yaml: --- Dates: class: Dates fields_ordered: [:start, :current, :end] and @conf = YAML::load( File.open( 'config.yml' ) ) #keeps parsed YAML #some code #block_name id a current 'top' name like 'Dates' @struct[:fields] = @conf[block_name]['fields_ordered'] #and later... private def init_hash(arr) Hash[*@struct[:fields].collect {|v| [v, arr[@struct[:fields].index(v)]]}.flatten] end It's method for converting csv line: lol, 123,lolo, 123.45 to hash using appopriate bean field names as keys > Kind regards > > robert -- Posted via http://www.ruby-forum.com/.