From: Robert Klemme Date: 2010-02-12T18:47:01+09:00 Subject: Re: String to symbol 2010/2/12 Sergey Sheypak : > 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. I understood that. But the point you are probably missing is this: you are mixing class and instance information in an unfortunate way: irb(main):031:0* d1 = Dates.new(:start=>1,:end=>2,:current=>3) => # irb(main):032:0> d1.start => 1 irb(main):033:0> d1.end => 2 irb(main):034:0> d1.current => 3 irb(main):035:0> d2 = Dates.new(:start=>99,:end=>98,:current=>97) => # irb(main):036:0> d2.start => 99 irb(main):037:0> d2.end => 98 irb(main):038:0> d2.current => 97 irb(main):039:0> d1.start # ooops! => 99 irb(main):040:0> d1.end # ooops! => 98 irb(main):041:0> d1.current # ooops! => 97 irb(main):042:0> You are changing state of an already created instance as a side effect of creating a new instance. This is not a good idea! >>> 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 referred to passing strings to #initialize. This certainly works. But the more dramatic issue persists (see above). Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/