From: tamouse mailing lists Date: 2013-02-24T14:58:19+09:00 Subject: Re: help with initialize method that involves readlines --f46d04426eda4d963c04d6721cba Content-Type: text/plain; charset=UTF-8 On Feb 23, 2013 5:54 PM, "Jordan G." wrote: > > i'm trying to set up a list or library of sorts that holds the info for > the objects in my program. Since i am working with atoms and molecules i > know all of the possible parameters, as in an atom with an atomic number > of 1 has to be hydrogen and the abbreviation has to be H. i feel like i > can set up my initialize method to read a specified line in an outside > file and use it for the @variables. i have an idea of how the process > would go but don't know how to write it out yet. below is > what i have in mind but it should be obvious where i'm confused because > i just describe what i want in human words > > class Atom > def initialize(x) > open(atom_name.txt, atom_abr.txt)readlines(x) > @atom_name = line x of atom_name.txt > @abbreviation = line x of atom_abr.txt > end > end > x will be a number 1 through 118 > > -- > Posted via http://www.ruby-forum.com/. > Look into yaml files --f46d04426eda4d963c04d6721cba Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Feb 23, 2013 5:54 PM, "Jordan G." <lists@ruby-forum.com> wrote:
>
> i'm trying to set up a list or library of sorts that holds the inf= o for
> the objects in my program. Since i am working with atoms and molecules= i
> know all of the possible parameters, as in an atom with an atomic numb= er
> of 1 has to be hydrogen and the abbreviation has to be H. i feel like = i
> can set up my initialize method to read a specified line in an outside=
> file and use it for the @variables. i have an idea of how the process<= br> > would go but don't know how to write it out yet. below is
> what i have in mind but it should be obvious where i'm confused be= cause
> i just describe what i want in human words
>
> class Atom
> =C2=A0 def initialize(x)
> =C2=A0 =C2=A0 open(atom_name.txt, atom_abr.txt)readlines(x)
> =C2=A0 =C2=A0 =C2=A0 @atom_name =3D line x of atom_name.txt
> =C2=A0 =C2=A0 =C2=A0 @abbreviation =3D line x of atom_abr.txt
> end
> end
> x will be a number 1 through 118
>
> --
> Posted via http://www.ruby-foru= m.com/.
>
Look into yaml files

--f46d04426eda4d963c04d6721cba--